Exemplo n.º 1
0
def get_pdb_ccd_open_babel_mol(pdb_mol):
    """ Generate an Open Babel representation of a PDB CCD entry

    Args:
        pdb_mol (:obj:`dict`): structure of a entry

    Returns:
        :obj:`openbabel.OBMol`: structure of a entry
    """
    if not pdb_mol['complete']:
        return None

    mol = openbabel.OBMol()

    for pdb_atom in pdb_mol['atoms']:
        atom = openbabel.OBAtom()
        atom.SetAtomicNum(pdb_atom['atomic_num'])
        atom.SetFormalCharge(pdb_atom['charge'])
        mol.AddAtom(atom)

    for pdb_bond in pdb_mol['bonds']:
        bond = openbabel.OBBond()
        bond.SetBegin(mol.GetAtom(pdb_bond['begin']))
        bond.SetEnd(mol.GetAtom(pdb_bond['end']))
        bond.SetBondOrder(pdb_bond['order'])
        assert mol.AddBond(bond)

    return mol
Exemplo n.º 2
0
def exchangeAtom(C, H, molTS, molFG, outfile, bondLength):
    # read write xyz file
    convTS, convFG = [ob.OBConversion() for i in range(2)]
    convTS.SetInAndOutFormats("xyz", "xyz")
    convFG.SetInAndOutFormats("xyz", "xyz")

    # builder
    builder = ob.OBBuilder()

    # define molecules, atoms and bond classes
    TS, FG = [ob.OBMol() for i in range(2)]
    atomH = ob.OBAtom()
    atomC = ob.OBAtom()
    bond = ob.OBBond()

    # read in xyz files
    convTS.ReadFile(TS, molTS)
    convFG.ReadFile(FG, molFG)

    # number of atoms in TS molecule
    numAtoms = TS.NumAtoms()

    # get hydrogen atom and its vector
    atomH = TS.GetAtom(H)
    atomC = TS.GetAtom(C)
    vec = ob.vector3(float(atomH.GetX()), float(atomH.GetY()),
                     float(atomH.GetZ()))

    # delete hydrogen atom
    TS.DeleteAtom(atomH)

    # put both molecules together (same coord system)
    TS += FG

    # making the bond
    builder.Connect(TS, C, numAtoms, vec, 1)

    bond = TS.GetBond(C, numAtoms)
    bond.SetLength(atomC, bondLength)

    # call opimizer
    #opt_mmff_FG(TS, numAtoms, outfile)

    convTS.WriteFile(TS, "single/" + outfile)

    # clear TS and FG molecule classes
    TS.Clear()
    FG.Clear()
Exemplo n.º 3
0
 def oasa_to_ob_bond(self, obond):
     pbond = openbabel.OBBond()
     pbond.SetBondOrder(obond.order)
     return pbond
Exemplo n.º 4
0
    def pic(self, filename, picformat='svg'):
        """
        Generates a graphical file with 2D-representation of the resonance structure
        """
        try:
            import openbabel as ob
        except:
            print "Cannot import openbabel"
            return

        #ValEl = {'H':1, 'B':3,'C':4,'N':5,'O':6,'F':7,'S':6}
        #ValEl = {'1':1, '5':3,'6':4,'7':5,'8':6,'9':7,'16':6}
        # Import Element Numbers
        ati = []
        Sym2Num = ob.OBElementTable()
        for a in self.symbols:
            ElNum = Sym2Num.GetAtomicNum(a)
            ati.append(ElNum)

        # Import connections
        conn = self.data

        mol = ob.OBMol()

        # Create atoms
        for a in ati:
            at = ob.OBAtom()
            at.SetAtomicNum(a)
            mol.AddAtom(at)

        # Create connections
        val = []
        total_LP = 0
        for i in range(len(conn)):
            total_LP += conn[i][i]

        for i in range(len(conn)):
            val.append(conn[i][i] * 2)
            for j in range(i):
                if conn[i][j] == 0:
                    continue
                val[i] += conn[i][j]
                val[j] += conn[i][j]
                atA = mol.GetAtomById(i)
                atB = mol.GetAtomById(j)

                b = ob.OBBond()
                b.SetBegin(atA)
                b.SetEnd(atB)
                b.SetBO(int(conn[i][j]))
                mol.AddBond(b)
        for i in range(len(conn)):
            atA = mol.GetAtomById(i)
            atAN = atA.GetAtomicNum()
            FormValEl = CountValenceEl(atAN)
            #if total_LP == 0:
            #    if atAN == 1:
            #        FullShell = 2
            #    else:
            #        FullShell = 8
            #    FormCharge = FormValEl + int(val[i]) - FullShell
            #else:
            FormCharge = int(FormValEl - val[i])
            #print "atAN, FormValEl, val[i], FullShell"
            #print atAN, FormValEl, val[i], FullShell
            #FormCharge = FormCharge % 2
            atA.SetFormalCharge(FormCharge)

        # Export file
        mol.DeleteNonPolarHydrogens()
        conv = ob.OBConversion()
        conv.SetOutFormat(picformat)
        conv.AddOption('C')
        conv.WriteFile(mol, filename)
Exemplo n.º 5
0
    def is_c_terminus(self, mol, atom, residue=True, convert_to_aa=False):
        """ Determine if an atom is an C-terminus

        Args:
            mol (:obj:`openbabel.OBMol`): molecule
            atom (:obj:`openbabel.OBAtom`): atom
            residue (:obj:`bool`, optional): if :obj:`True`, search for a residue (H instead of O- at C terminus)
            convert_to_aa (:obj:`bool`, optional): if :obj:`True`, convert COH to COOH

        Returns:
            :obj:`bool`: :obj:`True` if the atom is an C-terminus
        """
        if atom is None:
            return False

        # check atom is carbon
        if atom.GetAtomicNum() != 6:
            return False

        # check atom has charge 0
        if atom.GetFormalCharge() != 0:
            return False

        # check atom is bonded to 1 oxygen, 1 carbon, and 1 hydrogen atom (residue=True) or 1 oxygen (residue=False) atom
        other_atoms = [
            other_atom.GetAtomicNum()
            for other_atom in openbabel.OBAtomAtomIter(atom)
        ]
        tot_bond_order = sum(
            [bond.GetBondOrder() for bond in openbabel.OBAtomBondIter(atom)])
        other_atoms += [1] * (4 + atom.GetFormalCharge() - tot_bond_order)
        other_atoms.sort()
        if set(other_atoms).difference(set([1, 6, 8])):
            return False
        if 6 not in other_atoms or 8 not in other_atoms:
            return False
        if len(other_atoms) != 3:
            return False
        if residue and other_atoms[0] != 1:
            return False
        if not residue and other_atoms[1] != 8:
            return False

        # check bonds to carbon and hydrogen are single bonds and bond to oxygen is a double bond
        o_single_bonds = []
        o_double_bonds = []
        for bond in openbabel.OBAtomBondIter(atom):
            other_atom = bond.GetBeginAtom()
            if other_atom == atom:
                other_atom = bond.GetEndAtom()
            if other_atom.GetAtomicNum() == 8:
                if bond.GetBondOrder() == 1:
                    o_single_bonds.append((bond, other_atom))
                elif bond.GetBondOrder() == 2:
                    o_double_bonds.append((bond, other_atom))
                else:
                    return False
            elif bond.GetBondOrder() != 1:
                return False

        if residue and (len(o_single_bonds) != 0 or len(o_double_bonds) != 1):
            return False
        if not residue and (len(o_single_bonds) != 1
                            or len(o_double_bonds) != 1):
            return False

        # if not residue, check that single oxygen is bound to H
        if not residue:
            oxygen_atom = o_single_bonds[0][1]
            for bond in openbabel.OBAtomBondIter(oxygen_atom):
                other_atom = bond.GetBeginAtom()
                if other_atom == oxygen_atom:
                    other_atom = bond.GetEndAtom()
                if other_atom.GetIdx() != atom.GetIdx(
                ) and other_atom.GetAtomicNum() != 1:
                    return False

        # correct residue to amino acid
        if convert_to_aa:
            h_atom = None
            for other_atom in openbabel.OBAtomAtomIter(atom):
                if other_atom.GetAtomicNum() == 1:
                    h_atom = other_atom
                    break

            if h_atom is not None:
                h_atom.SetAtomicNum(8)
            else:
                o_atom = mol.NewAtom()
                o_atom.SetAtomicNum(8)
                o_atom.SetFormalCharge(0)

                bond = openbabel.OBBond()
                bond.SetBegin(atom)
                bond.SetEnd(o_atom)
                bond.SetBondOrder(1)
                assert mol.AddBond(bond)

        # return True
        return True