Created
August 8, 2012 12:57
-
-
Save cstein/3294891 to your computer and use it in GitHub Desktop.
Generating and depicting structures using the Open Babel API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getAminoAcids(include_protonated=False): | |
molecules = dict() | |
molecules['GLY'] = 'NCC(=O)O' | |
molecules['ALA'] = 'NC(C)C(=O)O' | |
molecules['SER'] = 'NC(CO)C(=O)O' | |
molecules['THR'] = 'NC(C(C)O)C(=O)O' | |
molecules['CYS'] = 'NC(CS)C(=O)O' | |
molecules['VAL'] = 'NC(C(C)C)C(=O)O' | |
molecules['LEU'] = 'NC(CC(C)C)C(=O)O' | |
molecules['ILE'] = 'NC(C(C)CC)C(=O)O' | |
molecules['MET'] = 'NC(CCSC)C(=O)O' | |
molecules['PRO'] = 'N1C(C(=O)O)CCC1' | |
molecules['PHE'] = 'NC(Cc1ccccc1)C(=O)O' | |
molecules['TYR'] = 'NC(Cc1cc(O)ccc1)C(=O)O' | |
molecules['TRP'] = 'NC(Cc1c2ccccc2nc1)C(=O)O' | |
molecules['ASP'] = 'NC(CC(=O)O)C(=O)O' | |
molecules['GLU'] = 'NC(CCC(=O)O)C(=O)O' | |
molecules['ASN'] = 'NC(CC(=O)N)C(=O)O' | |
molecules['GLN'] = 'NC(CCC(=O)N)C(=O)O' | |
molecules['HIS'] = 'NC(C(=O)O)Cc1cncn1' | |
molecules['LYS'] = 'NC(CCCCN)C(=O)O' | |
molecules['ARG'] = 'NC(CCCNC(=N)N)C(=O)O' | |
if include_protonated is True: | |
# add protonated versions of bases | |
molecules['HISp'] = 'NC(C(=O)O)Cc1c[nH+]cn1' | |
molecules['LYSp'] = 'NC(CCCC[NH3+])C(=O)O' | |
molecules['ARGp'] = 'NC(CCCNC(=[H2+])N)C(=O)O' | |
# add deprotonated versions of acids | |
molecules['ASPd'] = 'NC(CC(=O)[O-])C(=O)O' | |
molecules['GLUd'] = 'NC(CCC(=O)[O-])C(=O)O' | |
return molecules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
molecule_charge.py - Determine the charge of a molecule | |
""" | |
import sys | |
if( len(sys.argv) != 2 ): | |
print "Usage: molecule_charge <in.pdb>" | |
sys.exit() | |
file_in = sys.argv[1] | |
import openbabel | |
obConversion = openbabel.OBConversion() | |
obConversion.SetInFormat("pdb") | |
mol = openbabel.OBMol() | |
obConversion.ReadFile(mol, file_in) | |
# get the charges of the atoms | |
charge_model = openbabel.OBChargeModel.FindType("MMFF94") | |
charge_model.ComputeCharges(mol) | |
partial_charges = charge_model.GetPartialCharges() | |
print "%i" % int(sum(partial_charges)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openbabel | |
from obutil import OBStructureFromSmiles | |
from aminoacids import getAminoAcids | |
if __name__ == '__main__': | |
# for now just default to amino acids from the amino acids library | |
AA = getAminoAcids() | |
for k in AA: | |
OBStructureFromSmiles(AA[k], k) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def OBMolMinimize(mol): | |
"""Minimize a molecule | |
""" | |
ff = openbabel.OBForceField.FindForceField("MMFF94") | |
ff.Setup(mol) | |
ff.ConjugateGradients(100, 1.0e-5) | |
ff.GetCoordinates(mol) | |
return mol | |
def OBStructureFromSmiles(smilesstring, filename=None): | |
mol = openbabel.OBMol() | |
obConversion = openbabel.OBConversion() | |
obConversion.SetInAndOutFormats("smi", "pdb") | |
obConversion.ReadString(mol, smilesstring) | |
mol.AddHydrogens() #False, True, 7.4) | |
builder = openbabel.OBBuilder() | |
builder.Build(mol) | |
mol = OBMolMinimize(mol) | |
if filename is None: return mol | |
# save structures in subfolder molecules | |
obConversion.WriteFile(mol, "molecules/%s.pdb" % filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment