Пример #1
0
    def rmsd_to_me(self, other_conf):
        """Calculate the rms distance between this conformer and another one.

        :param other_conf: The other conformer to align.
        :type other_conf: MyConformer
        :return: The rmsd, a float.
        :rtype: float
        """

        # Make a new molecule.
        amol = Chem.MolFromSmiles(self.smiles, sanitize=False)
        amol = MOH.check_sanitization(amol)
        amol = MOH.try_reprotanation(amol)

        # Add the conformer of the other MyConformer object.
        amol.AddConformer(self.conformer(), assignId=True)
        amol.AddConformer(other_conf.conformer(), assignId=True)

        # Get the two confs.
        first_conf = amol.GetConformers()[0]
        last_conf = amol.GetConformers()[-1]

        # Return the RMSD.
        amol = MOH.try_deprotanation(amol)
        rmsd = AllChem.GetConformerRMS(amol,
                                       first_conf.GetId(),
                                       last_conf.GetId(),
                                       prealigned=True)

        return rmsd
Пример #2
0
    def smiles(self, noh=False):
        """Get the desalted, canonical smiles string associated with this
           object. (Not the input smiles!)

        :param noh: Whether or not hydrogen atoms should be included in the
           canonical smiles string., defaults to False
        :param noh: bool, optional
        :return: The canonical smiles string, or None if it cannot be
           determined.
        :rtype: str or None
        """

        # See if it's already been calculated.
        if noh == False:
            # They want the hydrogen atoms.
            if self.can_smi != "":
                # Return previously determined canonical SMILES.
                return self.can_smi
            else:
                # Need to determine canonical SMILES.
                try:
                    can_smi = Chem.MolToSmiles(self.rdkit_mol,
                                               isomericSmiles=True,
                                               canonical=True)
                except:
                    # Sometimes this conversion just can't happen. Happened
                    # once with this beast, for example:
                    # CC(=O)NC1=CC(=C=[N+]([O-])O)C=C1O
                    Utils.log("Warning: Couldn't put " + self.orig_smi + " (" +
                              self.name +
                              ") in canonical form. Got this error: " +
                              str(sys.exc_info()[0]) +
                              ". This molecule will be " + "discarded.")
                    self.can_smi = None
                    return None

                self.can_smi = can_smi
                return can_smi
        else:
            # They don't want the hydrogen atoms.
            if self.can_smi_noh != "":
                # Return previously determined string.
                return self.can_smi_noh

            # So remove hydrogens. Note that this assumes you will have called
            # this function previously with noh = False
            amol = copy.copy(self.rdkit_mol)
            amol = MOH.try_deprotanation(amol)
            self.can_smi_noh = Chem.MolToSmiles(amol,
                                                isomericSmiles=True,
                                                canonical=True)
            return self.can_smi_noh