Example #1
0
    def align(self, refmol):
        from rdkit.Chem.rdMolAlign import GetO3A
        from moleculekit.molecule import Molecule

        if isinstance(refmol, SmallMol):
            refmol = refmol._mol
        if isinstance(refmol, Molecule):
            refmol = SmallMol(refmol)._mol

        pyO3A = GetO3A(self._mol, refmol)
        rmsd = pyO3A.Align()
        logger.info('Alignment with a RMSD of {}'.format(rmsd))
Example #2
0
def untransformed_rmsd(reference,
                       probe,
                       sanitize=True,
                       uniquify=False,
                       reflect=True,
                       method='sub',
                       **kwargs):
    rdk_reference = _chimera_to_rdkit(reference, sanitize=sanitize)
    rdk_probe = _chimera_to_rdkit(probe, sanitize=sanitize)
    if method in ('sub', 'best'):
        matches = rdk_reference.GetSubstructMatches(rdk_probe,
                                                    uniquify=uniquify)
    elif method == 'o3a':
        rdk_reference2 = _chimera_to_rdkit(reference, sanitize=sanitize)
        rdk_probe2 = _chimera_to_rdkit(probe, sanitize=sanitize)
        FastFindRings(rdk_reference)
        FastFindRings(rdk_probe)
        reference_params = MMFFGetMoleculeProperties(rdk_reference)
        probe_params = MMFFGetMoleculeProperties(rdk_probe)
        o3a = GetO3A(rdk_probe2,
                     rdk_reference2,
                     probe_params,
                     reference_params,
                     maxIters=0,
                     reflect=reflect)
        matches = o3a.Matches()
    else:
        raise chimera.UserError('`method` must be sub, best or o3a')
    if not matches:
        raise chimera.UserError('Could not find any matches.')
    maps = [list(enumerate(match)) for match in matches]
    best_rmsd = 1000.
    for atom_map in maps:
        rmsd = AlignMol(rdk_probe,
                        rdk_reference,
                        -1,
                        -1,
                        atomMap=atom_map,
                        maxIters=0,
                        reflect=reflect)
        if rmsd < best_rmsd:
            best_rmsd = rmsd
    return best_rmsd
Example #3
0
File: util.py Project: prokia/htmd
def alignMol(smallmol, refmol):
    """
    Return a new SmallMol object aligned to a refmol that can be a htmd.smallmol.smallmol.SmallMol
    or rdkit.Chem.rdchem.Mol. It removes all the conformers stored in the original object.


    Parameters
    ----------
    smallmol: htmd.smallmol.smallmol.SmallMol
     The SmallMol object to align
    refmol: htmd.smallmol.smallmol.SmallMol or rdkit.Chem.rdchem.Mol
        The molecule to align to

    Return
    ------
    newsmallmol: htmd.smallmol.smallmol.SmallMol
        a new SmallMol aligned to reference molecule
    """

    from htmd.smallmol.smallmol import SmallMol
    from rdkit.Chem.rdMolAlign import GetO3A

    if isinstance(refmol, SmallMol):
        refmol = refmol.toRdkitMol(includeConformer=True)

    sm_rdkit = smallmol.toRdkitMol(includeConformer=True)

    pyO3A = GetO3A(sm_rdkit, refmol)
    rmsd = pyO3A.Align()
    print('Alignment with a RMSD of {}'.format(rmsd))
    coords_new = sm_rdkit.GetConformer().GetPositions()

    sm_new = SmallMol(smallmol, fixHs=False)
    sm_new.removeConformers()
    sm_new.coords = coords_new[:, :, np.newaxis]

    return sm_new
Example #4
0
def align_o3a(reference,
              probe,
              transform=True,
              sanitize=True,
              maxIters=50,
              reflect=False,
              **kwargs):

    rdk_reference = _chimera_to_rdkit(reference, sanitize=sanitize)
    rdk_probe = _chimera_to_rdkit(probe, sanitize=sanitize)
    FastFindRings(rdk_reference)
    FastFindRings(rdk_probe)
    reference_params = MMFFGetMoleculeProperties(rdk_reference)
    probe_params = MMFFGetMoleculeProperties(rdk_probe)
    o3a = GetO3A(rdk_probe,
                 rdk_reference,
                 prbPyMMFFMolProperties=probe_params,
                 refPyMMFFMolProperties=reference_params,
                 maxIters=maxIters,
                 reflect=reflect)
    rmsd, xform = o3a.Trans()
    if transform:
        _transform_molecule(probe, chimera_xform(xform[:3]))
    return rmsd