Hi Fredrik, thanks a lot for the reply, it worked perfectly. I'm pasting the script below, maybe it could be helpful to someone else.
Although, I believe the code "ob.OBTetrahedralStereo.Invert(config)" should be supported for sake of consistency (unless it's an issue with the 2.3.2 build in Ubuntu 13.10 repositories). Cheers, Stefano ----------------- """ Invert chirality of atoms matching a given SMARTS pattern NOTE: it doesn't work properly with SMARTS with more than one chiral centers """ import pybel ob = pybel.ob smarts = pybel.Smarts("c[C@H](C(=O)O)") outputfile = pybel.Outputfile('smi', 'converted.smi', overwrite=1) inmol = [ '[O-]C(=O)[C@H](c1cccnc1)C' ] for smi in inmol: canonical = pybel.readstring('smi', smi).write('can') mol = pybel.readstring('can', canonical) old = mol.__str__() matches = smarts.findall(mol) if matches: firstmatch = matches[0] print firstmatch for matchingatom in firstmatch: facade = ob.OBStereoFacade(mol.OBMol) # NOTE GetTetrahedralStereo uses 0-based counting # while pybel.smarts returns 1-based indices ts = facade.GetTetrahedralStereo(matchingatom-1) if ts: config = ts.GetConfig() if config.winding == 1: config.winding = 2 else: config.winding = 1 ts.SetConfig(config) else: print "\t\tNo match, passing on molecule:", mol outputfile.write(mol) new = mol.__str__() check = (old == new) print "STILL THE SAME?", check if check: print old outputfile.close() -------------------- On 06/18/2014 01:01 AM, Fredrik Wallner wrote: > Hi, > > Maybe someone with more insight into the specifics can give a more stable > answer, but what I’ve found is that you can invert a center with the > following code: > config.winding = 2 if config.winding == 1 else 1 > ts.SetConfig(config) > So replacing config.Invert() with these two lines will make your example work > at least… > > Kind regards, > Fredrik > 18 jun 2014 kl. 03:45 skrev Stefano Forli <fo...@scripps.edu>: > >> Hi everyone, >> >> I'm trying to invert the chirality of a chemical group using Python. I had >> searched quite >> a while before finding something that I could use (despite the fact the >> question showed up >> a few times in the mailing list). >> >> My starting points were a discussion on Blueobelisk[1] and a guide file[2] >> that Noel >> linked in an old mailing list thread but I couldn't find in the current >> release. >> The example in [2] didn't work in my case, and it seems to use deprecated >> .Set*ClockwiseStereo() functions, therefore, I tried the other one that's >> following the >> blessed way (correct me if I'm wrong) with OBStereoFacade. >> Here is the code, that works up to a certain point: >> >> ----- >> import pybel >> ob = pybel.ob >> >> smarts = pybel.Smarts("c[C@H](C(=O)O)") >> inverse = pybel.Smarts("c[C@@H](C(=O)O)") >> outputfile = pybel.Outputfile('smi', 'converted.smi', overwrite=1) >> >> inmol = [ '[O]C(=O)[C@H](c1cccnc1)C' ] >> for smi in inmol: >> mol = pybel.readstring('smi', smi) >> old = mol.__str__ >> matches = smarts.findall(mol) >> firstmatch = matches[0] >> if matches: >> print "MATCH" >> facade = ob.OBStereoFacade(mol.OBMol) >> for matchingatom in firstmatch: >> ts = facade.GetTetrahedralStereo(matchingatom) >> if ts: >> print "TS\t", ts >> config = ts.GetConfig() >> print "CONFIG\t", config >> # these commands will raise an error >> # ob.OBTetrahedralStereo.Invert(config) >> # ob.OBTetrahedralStereo_invert(config) >> config.Invert() >> >> ts.SetConfig(config) >> assert inverse.findall(mol), "Hasn't been inverted!" >> outputfile.write(mol) >> new = mol.__str__ >> print "STILL THE SAME?", old == new >> >> outputfile.close() >> ----- >> When attempting to invert the chirality, it fails with the following error: >> >> Traceback (most recent call last): >> File "invertChiralityFacade.py", line 24, in <module> >> config.Invert() >> AttributeError: 'OBTetrahedralConfig' object has no attribute 'Invert' >> >> I've tried all combinations mentioned here [3] and none of them worked. >> Besides, it seems >> here is no mention of the Invert function in openbabel.py. >> I would really appreciate any input on the matter. >> >> Thanks! >> >> Stefano >> >> >> [1] >> http://blueobelisk.shapado.com/questions/which-openbabel-dev-version-methods-should-be-used-for-altering-stereochemistry >> [2] >> http://www.filewatcher.com/p/openbabel-2.3.0.tar.gz.14321281/openbabel-2.3.0/doc/guide/_sources/UseTheLibrary/PythonExamples.txt.html >> [3] https://code.google.com/p/pythonocc/issues/detail?id=20 >> >> >> -- >> Stefano Forli, PhD >> >> Staff Scientist >> Molecular Graphics Laboratory >> Dept. of Integrative Structural >> and Computational Biology, MB-112F >> The Scripps Research Institute >> 10550 North Torrey Pines Road >> La Jolla, CA 92037-1000, USA. >> >> tel: (858) 784-2055 >> fax: (858) 784-2860 >> email: fo...@scripps.edu >> http://www.scripps.edu/~forli/ >> >> ------------------------------------------------------------------------------ >> HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions >> Find What Matters Most in Your Big Data with HPCC Systems >> Open Source. Fast. Scalable. Simple. Ideal for Dirty Data. >> Leverages Graph Analysis for Fast Processing & Easy Data Exploration >> http://p.sf.net/sfu/hpccsystems >> _______________________________________________ >> OpenBabel-discuss mailing list >> OpenBabel-discuss@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss > -- Stefano Forli, PhD Staff Scientist Molecular Graphics Laboratory Dept. of Integrative Structural and Computational Biology, MB-112F The Scripps Research Institute 10550 North Torrey Pines Road La Jolla, CA 92037-1000, USA. tel: (858) 784-2055 fax: (858) 784-2860 email: fo...@scripps.edu http://www.scripps.edu/~forli/ ------------------------------------------------------------------------------ Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards http://p.sf.net/sfu/Bonitasoft _______________________________________________ OpenBabel-discuss mailing list OpenBabel-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-discuss