|
39 | 39 | import os |
40 | 40 | import re |
41 | 41 | import element as elements |
| 42 | +import openbabel |
42 | 43 | from .graph import Vertex, Edge, Graph |
43 | 44 | from .group import GroupAtom, GroupBond, Group, ActionError |
44 | 45 | from .atomtype import AtomType, atomTypes, getAtomType |
45 | | - |
| 46 | + |
46 | 47 | ################################################################################ |
47 | 48 |
|
48 | 49 | class Atom(Vertex): |
@@ -439,7 +440,10 @@ def applyAction(self, action): |
439 | 440 | raise ActionError('Unable to update GroupBond: Invalid action {0}.'.format(action)) |
440 | 441 |
|
441 | 442 | ################################################################################ |
442 | | - |
| 443 | +SMILEwriter = openbabel.OBConversion() |
| 444 | +SMILEwriter.SetOutFormat('smi') |
| 445 | +SMILEwriter.SetOptions("i",SMILEwriter.OUTOPTIONS) # turn off isomer and stereochemistry information (the @ signs!) |
| 446 | + |
443 | 447 | class Molecule(Graph): |
444 | 448 | """ |
445 | 449 | A representation of a molecular structure using a graph data type, extending |
@@ -907,7 +911,6 @@ def toInChI(self): |
907 | 911 | Convert a molecular structure to an InChI string. Uses |
908 | 912 | `OpenBabel <http://openbabel.org/>`_ to perform the conversion. |
909 | 913 | """ |
910 | | - import openbabel |
911 | 914 | # This version does not write a warning to stderr if stereochemistry is undefined |
912 | 915 | obmol = self.toOBMol() |
913 | 916 | obConversion = openbabel.OBConversion() |
@@ -959,24 +962,21 @@ def toAugmentedInChIKey(self): |
959 | 962 | return key+'mult'+str(radicalNumber+1) |
960 | 963 | else: |
961 | 964 | return key |
962 | | - |
| 965 | + |
| 966 | + |
963 | 967 | def toSMILES(self): |
964 | 968 | """ |
965 | 969 | Convert a molecular structure to an SMILES string. Uses |
966 | 970 | `OpenBabel <http://openbabel.org/>`_ to perform the conversion. |
967 | 971 | """ |
968 | | - import pybel |
969 | | - mol = pybel.Molecule(self.toOBMol()) |
970 | | - return mol.write('smiles').strip() |
| 972 | + mol = self.toOBMol() |
| 973 | + return SMILEwriter.WriteString(mol).strip() |
971 | 974 |
|
972 | 975 | def toOBMol(self): |
973 | 976 | """ |
974 | 977 | Convert a molecular structure to an OpenBabel OBMol object. Uses |
975 | 978 | `OpenBabel <http://openbabel.org/>`_ to perform the conversion. |
976 | 979 | """ |
977 | | - |
978 | | - import openbabel |
979 | | - |
980 | 980 | cython.declare(atom=Atom, atom1=Atom, bonds=dict, atom2=Atom, bond=Bond) |
981 | 981 | cython.declare(index1=cython.int, index2=cython.int, order=cython.int) |
982 | 982 |
|
|
0 commit comments