Beispiel #1
0
def atoms_positions_parser(input):
    """
    :param input: The input string
    :type input: str
    :rtype: Molecule
    """
    lines = input.split('\n')

    element_table = OBElementTable()
    mol = OBMol()

    for line in lines:
        matches = search(atoms_positions_pattern, line)

        # Create the atom
        atom = mol.NewAtom()

        # Set the proper atomic number with respect of the atomic symbol
        atomic_number = element_table.GetAtomicNum(matches.group(2))
        atom.SetAtomicNum(atomic_number)

        # Set the atom vector
        x = float(matches.group(3)) * 0.529177
        y = float(matches.group(4)) * 0.529177
        z = float(matches.group(5)) * 0.529177
        atom.SetVector(x, y, z)

    return Molecule(mol)
Beispiel #2
0
 def ToCannonicalSmiles(self):
     atomCache={}
     mol=OBMol()
     for sourceAtom in self.atoms:
         atom=mol.NewAtom()
         atom.SetAtomicNum(sourceAtom.GetAtomicNum())
         if sourceAtom.IsAromatic():
             atom.SetAromatic()
             atom.SetSpinMultiplicity(2)
         atomCache[sourceAtom]=atom
     for sourceBond in self.bonds:
         mol.AddBond(atomCache[sourceBond.atom1].GetIdx(), atomCache[sourceBond.atom2].GetIdx(), sourceBond.GetBondOrder())
     writer=OBConversion()
     writer.SetInAndOutFormats("smi", "can")
     return writer.WriteString(mol).strip()
Beispiel #3
0
    def ToOBMol(self):
        atomCache={}
        mol=OBMol()
        mol.BeginModify()
        for sourceAtom in self.atoms:
            atom=mol.NewAtom()
            atom.SetAtomicNum(sourceAtom.GetAtomicNum())
            if sourceAtom.IsAromatic():
                atom.SetAromatic()
##                atom.SetSpinMultiplicity(2)
            atomCache[sourceAtom]=atom
        for sourceBond in self.bonds:
            mol.AddBond(atomCache[sourceBond.atom1].GetIdx(), atomCache[sourceBond.atom2].GetIdx(), sourceBond.GetBondOrder())
##        mol.SetAromaticPerceived()
        mol.AssignSpinMultiplicity()
##        mol.UnsetAromaticPerceived()
        mol.EndModify()
        return mol