Openff-toolkit: Add functionality to create OFFMols with specific indexing

Created on 1 Nov 2019  路  8Comments  路  Source: openforcefield/openff-toolkit

Is your feature request related to a problem? Please describe.
Many people have requested the ability to create OFFMols with specified atom orderings. Most commonly, this is in the context of Canonical, isomeric, explicit hydrogen, mapped SMILES, which we attach to OFF-submitted molecules in QCArchive. However, people have also requested the ability to reorder the atoms from a molecule that already has an indexing system (like, an SDF).

Describe the solution you'd like
This is two similar requests in one:

  • Molecule.from_object(obj, index_map=dict(current_idx:new_idx): Be able to read a molecule with a _defined_ indexing system (like, from SDF), but have the created OFFMol have a different atom/bond ordering.
  • Molecule.from_mapped_smiles(mapped_smiles): Read an explicit-hydrogen, fully mapped SMILES, and create an OFFMol with that atom ordering.

    • Needs to check+fail if H's aren't explicit.

For both functions, we'll need to resolve what to do if the map indices don't begin at 1, of if the numbering system has gaps. For now, a reasonable behavior is probably just "fail".

high high

Most helpful comment

I think it makes the most sense to always do this check at least against the supplied connectivity as there will be a case where we want to create a molecule from just the 3D geometry and connectivity data, like when generating new smiles strings to index the archive and the check should make sure that inferred bonds are the same as the defined connections without the bond orders.

All 8 comments

cc: @ChayaSt who has implemented functionality related to this previously.

@ChayaSt: Can you point to the code in cmiles that could be used as the basis for this?

The functionality that exists in cmiles will generate an oemol or rdmol with atoms ordered as in the qcmolecule
https://github.com/openforcefield/cmiles/blob/master/cmiles/utils.py#L88-L139
There is also a flag you can set (permute_xyz) if you want to keep the order of the qcschema mol to generate mapped SMILES or if you want to permute xyz to the canonical ordering of the toolkit you are using.

Assigning this to @jthorton as an onboarding task

This issue is very related to #462. We may consider fixing both of these at the same time.

Loading from a QCA molecule will go one of two ways.

  1. If the QCA mol _has_ CMILES, then we'll use Molecule.from_mapped_smiles(mapped_smiles), and we can load the QCA geometry directly into the OFFMol
  2. If the QCA mol _does not have_ CMILES, then we'll use #462's solution (let's call it Molecule.from_qca_molecule), which will need to either

    • graph-match the elements+coordinates (with implied connectivity) to a valid SMILES of the molecule; or

    • Infer the bond orders solely from bond-order-less connectivity and total molecule charge.

@j-wags and @jthorton, I want to point out that getting the connectivity graph from the mapped SMILES or connectivity table without checking if hydrogen migrated or if stereochemistry changed can create wonky molecules. It would make sense to have a check for these when loading a QCA geometry with the mapped SMILES.

Ah, good call. I remember that that was a problem previously. So when we鈥檙e loading from a tagged SMILES, we should do a check that the geometry-derived connectivity has the same bonds as the SMILES- derived geometry. The check could ignore bond orders, but just make sure that bonds are defined at all between the expected atoms.

I think it makes the most sense to always do this check at least against the supplied connectivity as there will be a case where we want to create a molecule from just the 3D geometry and connectivity data, like when generating new smiles strings to index the archive and the check should make sure that inferred bonds are the same as the defined connections without the bond orders.

Was this page helpful?
0 / 5 - 0 ratings