예제 #1
0
def LoadMolFromSmiles(smiles):
    """Returns an OBMol construcetd from an SMILES code"""
    mol=OBMol()
    loader=OBConversion()
    loader.SetInAndOutFormats("smi","smi")
    if not loader.ReadString(mol, smiles):
        return None
    mol.smilesCode=smiles
    return mol
예제 #2
0
def LoadMolFromSmiles(smiles):
    """Returns an OBMol construcetd from an SMILES code"""
    smiles = sorted(smiles.split("."), key=len)[-1] ## Strip salts
    mol=OBMol()
    loader=OBConversion()
    loader.SetInAndOutFormats("smi","smi")
    if not loader.ReadString(mol, smiles):
        return None
    mol.smilesCode=smiles
    return mol
예제 #3
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)]
예제 #4
0
def all_to_all():
    """Function to compare all to all"""
    # Set up the OpenBaebel conversion modules
    sdconv = OBConversion()
    ligref = OBMol()
    # Define the residues and the proteisn to analyse
    res_d, prot_list = get_dict("myFirstFile.txt")
    # Now read in the ligand
    sdconv.SetInFormat("sdf")
    notatend = sdconv.ReadFile(ligref, "../mols.sdf")
    out_d = {}
    counter = 0
    # Now read the ligand file
    while notatend:
        lig_name = ligref.GetTitle().strip(",")
        prot_name = lig_name.split("_")[0]
        if prot_name not in prot_list:
            ligref = OBMol()
            notatend = sdconv.Read(ligref)
            continue
        ligref.AddHydrogens()
        counter += 1
        print counter
        for j, my_prot in enumerate(prot_list):
            protref = read_prot(
                r"C:\www\Protoype\media_coninchi\pdb" + "\\" + my_prot +
                "al.pdb", res_d)
            # Get the reference dictionary
            refresdict = pp.getresiduedict(protref, res_d)
            # Update this dict, to only residues in the binding site
            new_d = get_fp(protref, ligref, res_d)
            # Make sure it is a unique name for the output
            while lig_name in out_d:
                lig_name = lig_name + "Z"
            # Add it to the dict
            out_d[lig_name + my_prot] = {}
            for res in new_d:
                # Assign each residue the scores for each molecule
                out_d[lig_name + my_prot][res] = new_d[res]
        # Make the ligand
        ligref = OBMol()
        notatend = sdconv.Read(ligref)
    # Now write the results out
    write_res(out_d, res_d)
예제 #5
0
파일: chem.py 프로젝트: zidarsk8/orange-bio
    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
예제 #6
0
def properties(str_data, in_format, add_hydrogens=False):
    # Returns a dict with the atom count, formula, heavy atom count,
    # mass, and spaced formula.
    if in_format == 'inchi' and not str_data.startswith('InChI='):
        # Inchi must start with 'InChI='
        str_data = 'InChI=' + str_data
        validate_start_of_inchi(str_data)
    mol = OBMol()
    conv = OBConversion()
    conv.SetInFormat(in_format)
    conv.ReadString(mol, str_data)

    if add_hydrogens:
        mol.AddHydrogens()

    props = {}
    props['atomCount'] = mol.NumAtoms()
    props['formula'] = mol.GetFormula()
    props['heavyAtomCount'] = mol.NumHvyAtoms()
    props['mass'] = mol.GetMolWt()
    props['spacedFormula'] = mol.GetSpacedFormula()

    return props
예제 #7
0
def one_to_many():
    """Function to take multiple confs of ONE ligand and generate their PLIFS against one template protein"""
    # Set up the OpenBaebel conversion modules
    sdconv = OBConversion()
    ligref = OBMol()
    # Define the residues and the proteisn to analyse
    res_d, prot_list = get_dict("myFirstFile.txt")
    # Now read in the ligand
    sdconv.SetInFormat("sdf")
    notatend = sdconv.ReadFile(ligref, "../out.sdf")
    out_d = {}
    counter = 0
    my_prot = "1qmz"
    protref = read_prot(
        r"C:\www\Protoype\media_coninchi\pdb" + "\\" + my_prot + "al.pdb",
        res_d)
    # Now read the ligand file
    while notatend:
        lig_name = ligref.GetTitle().strip(",")
        prot_name = lig_name.split("_")[0]
        ligref.AddHydrogens()
        counter += 1
        print counter
        # Get the reference dictionary
        refresdict = pp.getresiduedict(protref, res_d)
        # Update this dict, to only residues in the binding site
        new_d = get_fp(protref, ligref, res_d)
        # Add it to the dict
        out_d[lig_name + str(counter)] = {}
        for res in new_d:
            # Assign each residue the scores for each molecule
            out_d[lig_name + str(counter)][res] = new_d[res]
        # Make the ligand
        ligref = OBMol()
        notatend = sdconv.Read(ligref)
    # Now write the results out
    write_res(out_d, res_d)
예제 #8
0
    firstline = conflist.readline()
    mollisttemp = [line for line in conflist]
    mollist = []
    scorelist = []
    for mol in mollisttemp:
        mollist.append(mol.split(',')[0])
        scorelist.append(mol.split(',')[1])
    os.chdir('..')

    # opening the molecule files
    pbf = protein_ligand_folder + '/protein_bindingsite_fixed.mol2'
    conv = OBConversion()
    conv.SetInFormat("mol2")

    protfix = OBMol()
    protref = OBMol()
    ligref = OBMol()
    docklig = OBMol()
    dockprot = OBMol()

    conv.ReadFile(protfix, pbf)
    conv.ReadFile(protref, protein_reference)
    conv.ReadFile(ligref, ligand_reference)

    refresdict = getresiduedict(protref, residue_of_choice)
    refringdict = getringdict(protref)
    fixringdict = getringdict(protfix)

    ringinteraction(refresdict, refringdict, residue_of_choice, protref,
                    ligref)
예제 #9
0
        (*i).c->GetType(), (*i).d->GetType(), (*i).V, (*i).n, (*i).cosNPhi0,
        (*i).tor * RAD_TO_DEG, (*i).energy);
```
"""
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())
예제 #10
0
def django_run(target, opt="XTAL"):
    """Function to take multiple confs of ONE ligand and generate their PLIFS against one template protein"""
    # Set up the OpenBaebel conversion modules
    sdconv = OBConversion()
    ligref = OBMol()
    # Define the residues and the proteisn to analyse
    if os.path.isfile(
            os.path.join(os.path.split(sys.argv[0])[0], 'data/res_def.py')):
        res_d = [
            trans_res(x) for x in ast.literal_eval(
                open(
                    os.path.join(
                        os.path.split(sys.argv[0])[0],
                        'data/res_def.py')).read())[target.title].split()
        ]
    print res_d
    # Molecules
    # Now read in the ligand
    plif_method = PlifMethod()
    plif_method.text = "PYPLIF"
    feature_list = [
        "POLAR", "FACE", "EDGE", "ACCEPTOR", "DONOR", "NEGATIVE", "POSITIVE"
    ]
    try:
        plif_method.validate_unique()
        plif_method.save()
    except ValidationError:
        plif_method = PlifMethod.objects.get(text="PYPLIF")
    out_d = {}
    counter = 0
    # Create a file for the protein
    t = tempfile.NamedTemporaryFile(suffix=".pdb", delete=False)
    my_prot = Protein.objects.get(code=target.title + "TEMP")
    t.write(my_prot.pdb_info.name)
    t.close()
    protref = read_prot(t.name, res_d)
    t = tempfile.NamedTemporaryFile(suffix=".sdf", delete=False)
    t.close()
    sdconv.SetInFormat("sdf")
    if opt == "XTAL":
        mols = Molecule.objects.exclude(
            prot_id__code__contains=target.title).filter(
                prot_id__target_id=target)
    elif opt == "LLOOMMPPAA":
        mols = []
        sps = SynthPoint.objects.filter(target_id=target)
        for s in sps:
            mols.extend([m for m in s.mol_id.all()])
    else:
        print "UNKNOWN OPTION"
        return
    for dj_mol in mols:
        out_sd = Chem.SDWriter(t.name)
        out_sd.write(Chem.MolFromMolBlock(str(dj_mol.sdf_info)))
        out_sd.close()
        sdconv.ReadFile(ligref, t.name)
        # Now make the new plif
        new_plif = Plif()
        new_plif.mol_id = dj_mol
        new_plif.prot_id = my_prot
        new_plif.method_id = plif_method
        try:
            new_plif.validate_unique()
            new_plif.save()
        except ValidationError:
            new_plif = Plif.objects.get(mol_id=dj_mol,
                                        prot_id=my_prot,
                                        method_id=plif_method)
        lig_name = ligref.GetTitle().strip(",")
        prot_name = lig_name.split("_")[0]
        ligref.AddHydrogens()
        counter += 1
        refresdict = pp.getresiduedict(protref, res_d)
        new_d = get_fp(protref, ligref, res_d)
        for res in new_d:
            new_res = PlifRes()
            new_res.res_name = res[:3]
            new_res.res_num = int(res[3:])
            new_res.prot_id = my_prot
            try:
                new_res.validate_unique()
                new_res.save()
            except ValidationError:
                new_res = PlifRes.objects.get(res_name=res[:3],
                                              res_num=int(res[3:]),
                                              prot_id=my_prot)
            new_plif.res_id.add(new_res)
            for bit_num, bit in enumerate(new_d[res]):
                new_bit = PlifBit()
                new_bit.feature = feature_list[bit_num]
                new_bit.method_id = plif_method
                new_bit.res_id = new_res
                try:
                    new_bit.validate_unique()
                    new_bit.save()
                    my_fun(dj_mol, new_bit, new_plif, bit)
                except ValidationError:
                    new_bit = PlifBit.objects.get(
                        feature=feature_list[bit_num],
                        method_id=plif_method,
                        res_id=new_res)
                    new_bit.save()
                    new_plif.bit_id.add(new_bit)
                    my_fun(dj_mol, new_bit, new_plif, bit)

        ligref = OBMol()
        notatend = sdconv.Read(ligref)
예제 #11
0
kegg = Kegg.getInstance()
cids = kegg.get_all_cids()
print 'Found %d cids!' % len(cids)

smiles = open('smiles.txt', 'a')
nums = open('nums.txt', 'a')

if len(argv) < 2:
    i = 0
else:
    i = int(argv[1])

conv = OBConversion()
if not conv.SetInAndOutFormats('inchi', 'smi'):
    raise 'Problem with openbabel'

for j, cid in enumerate(cids[i:]):
    try:
        nums.write(str(j + i) + '\n')
        inchi = kegg.cid2inchi(cid)
        mol = OBMol()
        if not conv.ReadString(mol, inchi):
            print cid
        smiles.write(conv.WriteString(mol))
        #smiles.write(kegg.cid2smiles(cid) + '\n')
    except:
        print cid

smiles.close()
nums.close()