Skip to content

Commit

Permalink
more flexibility in Molecule to OpenFF conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
stefdoerr committed Jan 30, 2025
1 parent a15ad09 commit 2246a9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions moleculekit/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2495,13 +2495,20 @@ def getNeighbors(self, idx, bonds=None):
def _ix(self, resid, name):
return np.where((self.name == name) & (self.resid == resid))[0][0]

def toOpenFFMolecule(self):
def toOpenFFMolecule(self, sanitize=False, kekulize=False, assignStereo=True):
from moleculekit.smallmol.smallmol import SmallMol
from openff.toolkit.topology import Molecule as OFFMolecule
from openff.units import unit

sm = SmallMol(self, fixHs=False, removeHs=False, _logger=False)
sm.assignStereoChemistry(from3D=True)
sm = SmallMol(
self,
fixHs=False,
removeHs=False,
_logger=False,
sanitize=sanitize,
kekulize=kekulize,
assignStereo=assignStereo,
)

offmol = OFFMolecule.from_rdkit(sm._mol, hydrogens_are_explicit=True)
offmol.partial_charges = self.charge * unit.e
Expand Down
3 changes: 2 additions & 1 deletion moleculekit/smallmol/smallmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,8 +998,9 @@ def _fromMolecule(self, mol, _logger, **kwargs):
Chem.SanitizeMol(_mol)
if kwargs.get("kekulize", False):
Chem.Kekulize(_mol)
if kwargs.get("assignStereo", True):
Chem.AssignStereochemistryFrom3D(_mol)

Chem.AssignStereochemistryFrom3D(_mol)
if _logger:
logger.info(
f"Converted Molecule to SmallMol with SMILES: {Chem.MolToSmiles(_mol, kekuleSmiles=True)}"
Expand Down

0 comments on commit 2246a9f

Please sign in to comment.