Esempio n. 1
0
def otherinteractions(resdict, residuechoice, protein, ligand):
	for residue in OBResidueIter(protein):
		residuename = residue.GetName()
		if residuename in residuechoice:
			for atom in OBResidueAtomIter(residue):
				if not atom.IsHydrogen():
					for atomlig in OBMolAtomIter(ligand):
						if not atomlig.IsHydrogen():
							distance = atom.GetDistance(atomlig)
							if distance <= 4.5:
								if isnonpolar(atomlig) & isnonpolar(atom):
									resdict[residuename] |= bitarray('1000000')
								if distance <= 4.0:
									setformalcharge(atom)
									setformalcharge(atomlig)
									if (atom.GetFormalCharge()>0) & (atomlig.GetFormalCharge()<0):
										resdict[residuename] |= bitarray('0000010')
									if (atom.GetFormalCharge()<0) & (atomlig.GetFormalCharge()>0):
										resdict[residuename] |= bitarray('0000001')
									if distance <= 3.5:
										if atom.IsHbondDonor() & atomlig.IsHbondAcceptor():
											donorresidue = atom.GetResidue()
											for atomres in OBResidueAtomIter(donorresidue):
												if atomres.IsHbondDonorH() & atomres.IsConnected(atom):
													angle = atom.GetAngle(atomres, atomlig)
													if angle>135.0:
														resdict[residuename] |= bitarray('0001000')
										if atom.IsHbondAcceptor() & atomlig.IsHbondDonor():
											for atomres in OBMolAtomIter(ligand):
												if atomres.IsHbondDonorH() & atomres.IsConnected(atomlig):
													angle = atomlig.GetAngle(atomres, atom)
													if angle>135.0:
														resdict[residuename] |= bitarray('0000100')
Esempio n. 2
0
def hbonddockprot(resdict, residuechoice, protein, ligand):
    for residue in OBResidueIter(protein):
        residuename = residue.GetName()
        if residuename in residuechoice:
            for atom in OBResidueAtomIter(residue):
                if not atom.IsHydrogen():
                    for atomlig in OBMolAtomIter(ligand):
                        if not atomlig.IsHydrogen():
                            distance = atom.GetDistance(atomlig)
                            if distance <= 3.5:
                                if atom.IsHbondDonor(
                                ) & atomlig.IsHbondAcceptor():
                                    for neighborDon in OBAtomAtomIter(atom):
                                        if neighborDon.IsHydrogen():
                                            angle = atom.GetAngle(
                                                neighborDon, atomlig)
                                            if angle > 135.0:
                                                resdict[
                                                    residuename] |= bitarray(
                                                        '0001000')
                                if atom.IsHbondAcceptor(
                                ) & atomlig.IsHbondDonor():
                                    for neighborDon in OBAtomAtomIter(atomlig):
                                        if neighborDon.IsHydrogen():
                                            angle = atomlig.GetAngle(
                                                neighborDon, atom)
                                            if angle > 135.0:
                                                resdict[
                                                    residuename] |= bitarray(
                                                        '0000100')
Esempio n. 3
0
def otherinteractions(resdict, residuechoice, protein, ligand,
                      backboneatomlist):
    for residue in OBResidueIter(protein):
        residuename = residue.GetName()
        if residuename in residuechoice:
            for atom in OBResidueAtomIter(residue):
                if not atom.IsHydrogen():
                    for atomlig in OBMolAtomIter(ligand):
                        if not atomlig.IsHydrogen():
                            distance = atom.GetDistance(atomlig)
                            if distance <= 4.5:
                                if isnonpolar(atomlig) & isnonpolar(atom):
                                    #print "POLAR"
                                    resdict[residuename] |= bitarray('1000000')
                                if distance <= 4.0:
                                    setformalcharge(atom, backboneatomlist)
                                    fakebbatomlist = []
                                    setformalcharge(atomlig, fakebbatomlist)
                                    if (atom.GetFormalCharge() > 0) & (
                                            atomlig.GetFormalCharge() < 0):
                                        #print "NEGATIVE"
                                        resdict[residuename] |= bitarray(
                                            '0000010')
                                    if (atom.GetFormalCharge() < 0) & (
                                            atomlig.GetFormalCharge() > 0):
                                        #print "POSITIVE"
                                        resdict[residuename] |= bitarray(
                                            '0000001')
                                    if distance <= 3.5:
                                        if atom.IsHbondDonor(
                                        ) & atomlig.IsHbondAcceptor():
                                            for neighborDon in OBAtomAtomIter(
                                                    atom):
                                                if neighborDon.IsHydrogen():
                                                    angle = atom.GetAngle(
                                                        neighborDon, atomlig)
                                                    if angle > 135.0:
                                                        resdict[
                                                            residuename] |= bitarray(
                                                                '0001000')
#											donorresidue = atom.GetResidue()
#											for atomres in OBResidueAtomIter(donorresidue):
#												if atomres.IsHydrogen() & atomres.IsConnected(atom):
#													angle = atom.GetAngle(atomres, atomlig)
#													if angle>135.0:
#														resdict[residuename] |= bitarray('0001000')
                                        if atom.IsHbondAcceptor(
                                        ) & atomlig.IsHbondDonor():
                                            for neighborDon in OBAtomAtomIter(
                                                    atomlig):
                                                if neighborDon.IsHydrogen():
                                                    #print True
                                                    angle = atomlig.GetAngle(
                                                        neighborDon, atom)
                                                    #print angle
                                                    if angle > 135.0:
                                                        #print "ACCEPTOR"
                                                        resdict[
                                                            residuename] |= bitarray(
                                                                '0000100')
Esempio n. 4
0
 def InitializeFragment(self, atomicNum):
     mol=OBMol()
     atom=Atom(self, atomicNum)
     for mol in self.miner.GetAllMolecules():
         for a in OBMolAtomIter(mol):
             if atom.Match(a):
                 self.embedings.append(Embeding({atom.atomIndex : a.GetIdx()}, molecule=mol, fragment=self))
Esempio n. 5
0
def hbonddockprot(resdict, residuechoice, protein, ligand):
	for residue in OBResidueIter(protein):
		if residue.GetName() in residuechoice:
			for atom in OBResidueAtomIter(residue):
				if not atom.IsHydrogen():
					for atomlig in OBMolAtomIter(ligand):
						if not atomlig.IsHydrogen():
							distance = atom.GetDistance(atomlig)
							if distance <= 3.5:
								if atom.IsHbondDonor() & atomlig.IsHbondAcceptor():
									donorresidue = atom.GetResidue()
									for atomres in OBResidueAtomIter(donorresidue):
										if atomres.IsHbondDonorH() & atomres.IsConnected(atom):
											angle = atom.GetAngle(atomres, atomlig)
											if angle>135.0:
												resdict[residue.GetName()] |= bitarray('0001000')
								if atom.IsHbondAcceptor() & atomlig.IsHbondDonor():
									for atomres in OBMolAtomIter(ligand):
										if atomres.IsHbondDonorH() & atomres.IsConnected(atomlig):
											angle = atomlig.GetAngle(atomres, atom)
											if angle>135.0:
												resdict[residue.GetName()] |= bitarray('0000100')
Esempio n. 6
0
def type_mof(filename, output_dir, ff="uff", output_files=True):

    obconversion = OBConversion()
    obconversion.SetInAndOutFormats("cif", "xyz")
    obmol = OBMol()

    # Read MOF file and unit cell and write xyz file
    obconversion.ReadFile(obmol, filename)
    unitcell = openbabel.toUnitCell(obmol.GetData(openbabel.UnitCell))
    uc = [
        unitcell.GetA(),
        unitcell.GetB(),
        unitcell.GetC(),
        unitcell.GetAlpha(),
        unitcell.GetBeta(),
        unitcell.GetGamma()
    ]
    obconversion.WriteFile(obmol, 'mof_tmp.xyz')

    # Replicate unit cell using angstrom
    mol = Molecule(read='mof_tmp.xyz')
    mol.set_cell(uc)
    n_atoms = len(mol.atoms)

    mol333 = mol.replicate([3, 3, 3], center=True)
    print(mol333.cell)
    mol333.write('mof333.cif', cell=mol333.cell.to_list())

    # Type FF
    obconversion.ReadFile(obmol, 'mof333.cif')
    ff = OBForceField.FindForceField("UFF")
    if not ff.Setup(obmol):
        print("Error: could not setup force field")
    ff.GetAtomTypes(obmol)

    # Get atom types for the middle cell
    types = []
    for atom_idx, obatom in enumerate(OBMolAtomIter(obmol)):
        if atom_idx >= n_atoms * 13 and atom_idx < n_atoms * 14:
            ff_atom_type = obatom.GetData("FFAtomType").GetValue()
            types.append(ff_atom_type)

    if output_files:
        mof_name = os.path.splitext(os.path.basename(filename))[0]
        with open(os.path.join(output_dir, mof_name + "-obabel.log"),
                  'w') as f:
            f.write("NOTE: types order is the same as the CIF input file.\n")
            f.write("types= %s" % str(types))

    uniq_types = sorted(set(types))
    return [str(i) for i in uniq_types]
Esempio n. 7
0
    def Initialize(self):
        """Initializes the search"""
        self.initialFragments=[]
        self.rings={}
        self.atomCount={}
        self.canonicalPruningSet={}
        candidates=[]
        ringCandidates=[]
        for mol in self.GetAllMolecules():
            mol.rings=self.rings[mol]=list(mol.GetSSSR())
            for ring in mol.rings:
                ring.fingerprint=set([mol.GetAtom(i).GetAtomicNum() for i in ring._path])
##            for ring in mol.rings:
##                candidates.append(FragmentExtensionByRing([ring],[Embeding(molecule=mol)]))
        
        for mol in self.GetAllMolecules():
            for atom in OBMolAtomIter(mol):
                self.atomCount[atom.GetAtomicNum()]= self.atomCount[atom.GetAtomicNum()]+1 if  atom.GetAtomicNum() in self.atomCount else 1
                if not (atom.GetAtomicNum()==6 and atom.IsInRing()):
                    candidates.append(FragmentExtensionByAtom(atom.GetAtomicNum(), atom.IsAromatic(), [atom.GetIdx()], [Embeding(molecule=mol)]))
        groups=[]
        candidates.sort(lambda a,b: cmp(self.atomCount[a.atomicNum], self.atomCount[b.atomicNum]))
        for extension in candidates:
            for ext in groups:
                if type(ext)==type(extension) and ext.IsEquivalent(extension):
                    ext.MergeFrom(extension)
                    break
            else:
                groups.append(extension)
        lst=self.atomCount.items()
        lst.sort(lambda a,b:cmp(a[1], b[1]))
        self.initialFragments=[]
        lst=[t[0] for t in lst]
        for extension in groups:
            if type(extension)==FragmentExtensionByAtom:
                f=Fragment(miner=self, excludeAtomList=lst[:lst.index(extension.atomicNum)])
            else:
                f=Fragment(miner=self)
            extension.Extend(f)
            self.initialFragments.append(f)
##        self.initialFragments.reverse()
##        excludeList=[]
##        for atom, c in lst:
##            f=Fragment(miner=self, excludeAtomList=excludeList)
##            f.InitializeFragment(atom)
##            self.initialFragments.append(f)
##            excludeList.append(atom)
        self.activeSet=set(self.active)
        self.inactiveSet=set(self.inactive)
Esempio n. 8
0
def get_atomic_fragments_from_mol(xyz):
    """Get the fragments around each atom

    Args:
        xyz (string): XYZ file for the
    """

    # Read in the molecule
    mol = OBMol()
    converter.ReadString(mol, xyz)

    # Determine ring types
    OBRingTyper().AssignTypes(mol)

    # For each atom, get its local environment
    return [get_atomic_environment(atom) for atom in OBMolAtomIter(mol)]
Esempio n. 9
0
def otherinteractions2(resdict, residuechoice, protein, ligand,
                       backboneatomlist):
    RigidHdonors = ['HIS', 'GLN', 'ASN', 'ARG', 'TRP']
    for residue in OBResidueIter(protein):
        residuename = residue.GetName()
        if residuename in residuechoice:
            for atom in OBResidueAtomIter(residue):
                if not atom.IsHydrogen():
                    for atomlig in OBMolAtomIter(ligand):
                        print atomlig
                        if not atomlig.IsHydrogen():
                            distance = atom.GetDistance(atomlig)
                            if distance <= 4.5:
                                if isnonpolar(atomlig) & isnonpolar(atom):
                                    resdict[residuename] |= bitarray('1000000')
                                if distance <= 4.0:
                                    setformalcharge(atom, backboneatomlist)
                                    fakebbatomlist = []
                                    setformalcharge(atomlig, fakebbatomlist)
                                    if (atom.GetFormalCharge() > 0) & (
                                            atomlig.GetFormalCharge() < 0):
                                        resdict[residuename] |= bitarray(
                                            '0000010')
                                    if (atom.GetFormalCharge() < 0) & (
                                            atomlig.GetFormalCharge() > 0):
                                        resdict[residuename] |= bitarray(
                                            '0000001')
                                    if distance <= 3.5:
                                        if residuename[:3] in RigidHdonors:
                                            if atom.IsHbondDonor(
                                            ) & atomlig.IsHbondAcceptor():
                                                for neighborDon in OBAtomAtomIter(
                                                        atom):
                                                    if neighborDon.IsHydrogen(
                                                    ):
                                                        angle = atom.GetAngle(
                                                            neighborDon,
                                                            atomlig)
                                                        if angle > 135.0:
                                                            resdict[
                                                                residuename] |= bitarray(
                                                                    '0001000')
                                        elif atom.GetIdx() in backboneatomlist:
                                            if atom.IsHbondDonor(
                                            ) & atomlig.IsHbondAcceptor():
                                                for neighborDon in OBAtomAtomIter(
                                                        atom):
                                                    if neighborDon.IsHydrogen(
                                                    ):
                                                        angle = atom.GetAngle(
                                                            neighborDon,
                                                            atomlig)
                                                        if angle > 135.0:
                                                            resdict[
                                                                residuename] |= bitarray(
                                                                    '0001000')
                                        if atom.IsHbondAcceptor(
                                        ) & atomlig.IsHbondDonor():
                                            for neighborDon in OBAtomAtomIter(
                                                    atomlig):
                                                if neighborDon.IsHydrogen():
                                                    angle = atomlig.GetAngle(
                                                        neighborDon, atom)
                                                    if angle > 135.0:
                                                        resdict[
                                                            residuename] |= bitarray(
                                                                '0000100')
Esempio n. 10
0
def otherinteractions(l_bit, l_res_choices, st_protein, st_lig,
                      l_serial_atom_backbone):
    for residue in OBResidueIter(st_protein):
        residuename = residue.GetName()
        if residuename in l_res_choices:
            for atom in OBResidueAtomIter(residue):
                if not atom.IsHydrogen():
                    for atomlig in OBMolAtomIter(st_lig):
                        if not atomlig.IsHydrogen():
                            distance = atom.GetDistance(atomlig)
                            if distance <= 4.5:
                                if isnonpolar(atomlig) & isnonpolar(atom):
                                    l_bit[residuename] |= bitarray('1000000')
                                if distance <= 4.0:
                                    setformalcharge(atom,
                                                    l_serial_atom_backbone)
                                    fakebbatomlist = []
                                    setformalcharge(atomlig, fakebbatomlist)
                                    if (atom.GetFormalCharge() > 0) & (
                                            atomlig.GetFormalCharge() < 0):
                                        l_bit[residuename] |= bitarray(
                                            '0000010')
                                    if (atom.GetFormalCharge() < 0) & (
                                            atomlig.GetFormalCharge() > 0):
                                        l_bit[residuename] |= bitarray(
                                            '0000001')
                                    if distance <= 3.5:
                                        if atom.IsHbondDonor(
                                        ) & atomlig.IsHbondAcceptor():
                                            for neighborDon in OBAtomAtomIter(
                                                    atom):
                                                if neighborDon.IsHydrogen():
                                                    for neighborAcc in OBAtomAtomIter(
                                                            atomlig):
                                                        angle = neighborAcc.GetAngle(
                                                            atomlig,
                                                            neighborDon)
                                                        if angle > 135.0:
                                                            l_bit[
                                                                residuename] |= bitarray(
                                                                    '0001000')

#											donorresidue = atom.GetResidue()
#											for atomres in OBResidueAtomIter(donorresidue):
#												if atomres.IsHydrogen() & atomres.IsConnected(atom):
#													angle = atom.GetAngle(atomres, atomlig)
#													if angle>135.0:
#														l_bit[residuename] |= bitarray('0001000')
                                        if atom.IsHbondAcceptor(
                                        ) & atomlig.IsHbondDonor():
                                            for neighborDon in OBAtomAtomIter(
                                                    atomlig):
                                                if neighborDon.IsHydrogen():
                                                    for neighborAcc in OBAtomAtomIter(
                                                            atom):
                                                        angle = neighborAcc.GetAngle(
                                                            atom, neighborDon)
                                                        if angle > 135.0:
                                                            l_bit[
                                                                residuename] |= bitarray(
                                                                    '0000100')
```
"""
import sys
sys.path.insert(0, "/usr/local/lib/python3.6/site-packages")

import os

from openbabel import OBMol, OBConversion, OBMolAtomIter, OBForceField

mof = "csdac-linkers-cml/uio66-HNC3-alkane.cml"

obconversion = OBConversion()
obconversion.SetInAndOutFormats("cml", "cml")
obmol = OBMol()
obconversion.ReadFile(obmol, mof)
ff = OBForceField.FindForceField("UFF")
ff.SetLogToStdOut()
ff.SetLogLevel(3)

if not ff.Setup(obmol):
    print("Error: could not setup force field")
ff.GetAtomTypes(obmol)

for atom_idx, obatom in enumerate(OBMolAtomIter(obmol)):
    ff_atom_type = obatom.GetData("FFAtomType").GetValue()
    print(ff_atom_type)

print(ff.Energy(True))
print(ff.E_Torsion())
print(obmol.GetEnergy())