pybel / pybel

🌶️ An ecosystem in Python for working with the Biological Expression Language (BEL)
http://pybel.readthedocs.io
MIT License
131 stars 31 forks source link

Issue converting xyz to smiles #362

Closed SebGay closed 5 years ago

SebGay commented 5 years ago

Hello there, I am working with two large databases and currently need to obtain smiles strings for a large number (133k) of extended xyz files.

I have install pybel with no issues, and am able to read a sample xyz file with ease using which looks like

8
charge=0=
C         -4.58735        0.92696        0.00000
C         -3.11050        0.92696        0.00000
H         -4.93786        1.78883        0.58064
H         -4.93786       -0.00682        0.45608
H         -4.93786        0.99888       -1.03672
H         -2.75999        0.85505        1.03672
H         -2.75998        1.86075       -0.45608
H         -2.75998        0.06509       -0.58064

using mol = pybel.readfile("xyz","ethane.xyz").next() I am then able to verify it has read the molecule by using

mol.exactmass
mol.formula

etc.

Ideally I would like to be able to simply get the smile as a string in my python program, but could possibly live with writing a textfile to disk (or a virtual file to memory) and reading it again. My database file has all the molecules in the one file but they can be separated.

When I try to use mol.write("smi","out.txt") the output textfile simply reads CC charge=0= Where I would like it to read H]C([H])([H])C([H])([H])[H]

Therefore, how would it be possible to:

  1. Get the smile string for an molecule stored as an XYZ
  2. Get this string as a return value rather than written to file
  3. Read an XYZ file containing my full database (I suspect this will involve .next() and I should be able to nut this out)

If it at all helps I can easily have these molecules as ASE Atoms object.

Thank you very much for any help!

cthoyt commented 5 years ago

Hi @sgay,

I'm sorry for the confusion, but I think you're looking for OpenBabel, and not PyBEL (we're working with Biological Expression Language here)

Please check their repository at https://github.com/openbabel/openbabel and more specifically https://github.com/openbabel/openbabel/tree/master/scripts/python

SebGay commented 5 years ago

Sorry about that, thanks for your help!