openforcefield / cmiles

Generate canonical molecule identifiers for quantum chemistry database
https://cmiles.readthedocs.io
MIT License
23 stars 7 forks source link

Better parsing of molecule inputs #40

Open mattwthompson opened 4 years ago

mattwthompson commented 4 years ago

Arguably trivial but it would be nice to handle the wrong input separately from checking that toolkit(s) are installed. Here I accidentally pass in an OpenFF Molecule and confused myself since I knew I had the toolkits installed


In [1]: import cmiles

In [2]: from openforcefield.topology.molecule import Molecule
Warning: Unable to load toolkit 'AmberTools'.
_ColormakerRegistry()

In [3]: cmiles.utils.mol_to_smiles(Molecule.from_smiles('C'))
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-3-f0a9fb86fb26> in <module>
----> 1 cmiles.utils.mol_to_smiles(Molecule.from_smiles('C'))

~/software/cmiles/cmiles/utils.py in mol_to_smiles(molecule, **kwargs)
    165     """
    166     molecule = copy.deepcopy(molecule)
--> 167     toolkit = _set_toolkit(molecule)
    168     if has_atom_map(molecule):
    169         remove_atom_map(molecule)

~/software/cmiles/cmiles/utils.py in _set_toolkit(molecule)
    556         import cmiles._cmiles_rd as toolkit
    557     else:
--> 558         raise RuntimeError("Must have openeye or rdkit installed")
    559     return toolkit
    560

RuntimeError: Must have openeye or rdkit installed

In [4]: cmiles.utils.mol_to_smiles(Molecule.from_smiles('C').to_openeye())
Out[4]: '[H:2][C:1]([H:3])([H:4])[H:5]'