stsouko / CGRtools

CGRs, molecules and reactions manipulation
GNU Lesser General Public License v3.0
2 stars 0 forks source link

Output SDF file is invalid and unreadable #159

Closed Sarif-HK closed 3 years ago

Sarif-HK commented 3 years ago

The issue:

When I write a molecule container to an mol sdf file with SDFWrite then try opening this file in any molecular editor whatsoever(Accelrys draw, rdkit lib, etc) the editor will either error or return a blank canvas.

The code and output:

m = CreateMoleculeFromString(message.content)
CGR = m.compose(m)
with SDFWrite('molecule.mol') as w:
    w.write(CGR)

which creates a file


 10 10  0  0  0  0            999 V2000
    1.8347    1.7649    0.0000 C   0  0  0  0  0  0  0  0  0  1  0  0
    0.8175    2.0469    0.0000 C   0  0  0  0  0  0  0  0  0  2  0  0
    0.0000    1.3778    0.0000 C   0  0  0  0  0  0  0  0  0  3  0  0
    0.4512    0.4166    0.0000 C   0  0  0  0  0  0  0  0  0  4  0  0
    1.2496    0.0220    0.0000 C   0  0  0  0  0  0  0  0  0  5  0  0
    1.8111    0.7009    0.0000 C   0  0  0  0  0  0  0  0  0  6  0  0
    1.3813   -0.6984    0.0000 C   0  0  0  0  0  0  0  0  0  7  0  0
    2.0824   -1.1896    0.0000 C   0  0  0  0  0  0  0  0  0  8  0  0
    2.1004   -1.9993    0.0000 C   0  0  0  0  0  0  0  0  0  9  0  0
    2.8603   -2.4418    0.0000 C   0  0  0  0  0  0  0  0  0 10  0  0
  1  2  2  0  0  0  0
  1  6  2  0  0  0  0
  2  3  2  0  0  0  0
  3  4  2  0  0  0  0
  4  5  2  0  0  0  0
  5  6  2  0  0  0  0
  5  7  1  0  0  0  0
  7  8  1  0  0  0  0
  8  9  1  0  0  0  0
  9 10  1  0  0  0  0
M  END
$$$$

which im unable to open.

Conclusion

Am I using SDFWrite wrong? Am I using .compose wrong? Any help would be very useful. Thanks for your time and sorry if this doesnt fit the issue guidelines for this project. I would like to add that the molecule container seems valid because I can run operations on it, such as printing it to an svg image.

stsouko commented 3 years ago

this CGR = m.compose(m) creates cgr graph, but without any dynamic atom/bond. if you want cgr try to compose different molecules with correct atom-to-atom mapping (e.g. tautomers) image

SDF file is valid, but contains invalid atom valence image

try to rename mol to sdf. sdf contains mol with $$$$ line in the end.

tagirshin commented 3 years ago

Hello, thanks for your comment! Well, first of all what is the function CreateMoleculeFromString(message.content) or at least which output does it give? If you already have molecule, you can directly pass it to SDFWrite method. For example, imagine we have SMILES string C1=CC=CC=C1CCCC:

from CGRtools.files import SMILESRead, SDFWrite

smiles = 'C1=CC=CC=C1CCCC'
smiles_to_mol = SMILESRead.create_parser(remap=False, ignore=True)  
mol = smiles_to_mol(smiles)
with SDFWrite('output_mol.sdf') as output:
    output.write(mol)
Sarif-HK commented 3 years ago

this CGR = m.compose(m) creates cgr graph, but without any dynamic atom/bond. if you want cgr try to compose different molecules with correct atom-to-atom mapping (e.g. tautomers) image

SDF file is valid, but contains invalid atom valence image

try to rename mol to sdf. sdf contains mol with $$$$ line in the end.

this fixed it, apparently my function wrote weird valences for phenyl groups, thank you.