From: Noel O'B. <bao...@gm...> - 2010-12-07 16:09:20
|
The InChI key is available as an option of the InChI format: http://baoilleach.blogspot.com/2008/10/generating-inchis-mini-me-inchikey.html So no need for SMILES... BTW, it's handier for me if you send OB questions to the mailing list rather than directly to me. It gives someone else a chance to answer..:-) - Noel On 7 December 2010 15:47, Ken Smith <k.w...@qu...> wrote: > Hi Noel > > Just a quick (probably stupid) question. > > I need to create a table of InChIs and InChIKeys for all the elements and > their common isotopes. I couldn't see an easy way of using OpenBabel > (python) to generate the keys from hand-cranked InChIs, so I tried using > SMILES (which means I need to learn the SMILES format, and I'm then > constrained by its limitations). When I use it though, I get some > disconnected metal errors that (as a non-chemist) I don't understand, and > the InChI I get has a hydrogen added. Can you point me in the right > direction? My preference is to avoid having to go via SMILES, but if not, a > SMILES workaround suffice for the time being. > > Cheers, > > Ken > > > E.g. below is some trivial python code to generate the InChI(Keys) from > SMILES. > > > python getInchiFromSmiles.py [Na] > > ============================== > *** Open Babel Warning in InChI code > #0 :Metal was disconnected > ============================== > *** Open Babel Warning in InChI code > #0 :Metal was disconnected > InChI=1S/Na.H > MPMYQQHEHYDOCL-UHFFFAOYSA-N > > > > > import openbabel as ob > import sys > > def getInChIAndInChIKey(smilesString): > conv = ob.OBConversion() > conv.SetInAndOutFormats("smi", "inchi") > > mol = ob.OBMol() > conv.ReadString(mol, smilesString) > inchi = conv.WriteString(mol).rstrip() > conv.SetOptions("K", conv.OUTOPTIONS) > inchikey = conv.WriteString(mol).rstrip() > return(inchi, inchikey) > > > def main(argv = None): > if argv is None: > argv = sys.argv > > if len(argv) != 2: > sys.exit("Usage: getInchiFromSmiles.py <SMILES format>") > > smiles = argv[1] > inchi, inchikey = getInChIAndInChIKey(smiles) > > print inchi > print inchikey > > return 0 > > > > if __name__ == '__main__': > main() > > > P.S. I'd also like to be able to represent protonated hydrogen (H3+), but > I've no idea how to represent that in SMILES. Presumably in InChI I use the > protonation layer if I want to hand-crank the InChI... > > > |