Skip to content

Commit 0117794

Browse files
committed
Fix to the notebook, as previously it wasnt able to read mol v2
1 parent 76cbe52 commit 0117794

File tree

1 file changed

+90
-4
lines changed

1 file changed

+90
-4
lines changed

INCHI-1-DOC/Notebooks/Molecular_inorganics/Geometries/molsimplify_test_v1.ipynb

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": 2,
23+
"execution_count": null,
2424
"id": "32069b9b",
2525
"metadata": {},
2626
"outputs": [],
2727
"source": [
2828
"import os\n",
2929
"import molSimplify\n",
30-
"\n",
30+
"from openbabel import openbabel\n",
3131
"from molSimplify.Classes import mol3D"
3232
]
3333
},
3434
{
3535
"cell_type": "code",
36-
"execution_count": 4,
36+
"execution_count": null,
3737
"id": "604aa4ca",
3838
"metadata": {},
3939
"outputs": [
@@ -70,6 +70,7 @@
7070
],
7171
"source": [
7272
"#Example with one file\n",
73+
"#this seems to work only with mol v2\n",
7374
"\n",
7475
"filename = \"./data/cis_platin.mol\"\n",
7576
"complex_mol = mol3D()\n",
@@ -79,7 +80,80 @@
7980
},
8081
{
8182
"cell_type": "code",
82-
"execution_count": 6,
83+
"execution_count": null,
84+
"id": "f0f589b8",
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
88+
"filename = \"./data/cis_platin.mol\"\n",
89+
"\n",
90+
"test_mol = openbabel.OBMol()\n",
91+
"\n",
92+
"# Create an OBConversion object\n",
93+
"obConversion = openbabel.OBConversion()\n",
94+
"\n",
95+
"# Set the input format ('mol') and output format ('xyz')\n",
96+
"obConversion.SetInFormat(\"mol\")\n",
97+
"obConversion.SetOutFormat(\"xyz\")\n",
98+
"\n",
99+
"if not obConversion.ReadFile(test_mol, filename):\n",
100+
" print(\"Error: Could not read the mol file.\")\n",
101+
"else:\n",
102+
" xyz_string = obConversion.WriteString(test_mol)\n",
103+
"\n",
104+
" complex_mol = mol3D()\n",
105+
" complex_mol.readfromstring(xyz_string)\n",
106+
" print(complex_mol.get_geometry_type())"
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": null,
112+
"id": "cf526836",
113+
"metadata": {},
114+
"outputs": [],
115+
"source": [
116+
"directory = './data'\n",
117+
"\n",
118+
"absolute_file_paths = [os.path.abspath(os.path.join(directory, f)) for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f)) and \"mol\" in f and not \"xyz\" in f]\n",
119+
"\n",
120+
"tmp_mol = openbabel.OBMol()\n",
121+
"\n",
122+
"# Create an OBConversion object\n",
123+
"obConversion = openbabel.OBConversion()\n",
124+
"\n",
125+
"# Set the input format ('mol') and output format ('xyz')\n",
126+
"obConversion.SetInFormat(\"mol\")\n",
127+
"obConversion.SetOutFormat(\"xyz\")\n",
128+
"\n",
129+
"for cur_fn in absolute_file_paths:\n",
130+
" \n",
131+
" complex_mol = mol3D()\n",
132+
"\n",
133+
" try:\n",
134+
" print(\"----------------------\")\n",
135+
" print(cur_fn)\n",
136+
" \n",
137+
" if not obConversion.ReadFile(tmp_mol, filename):\n",
138+
" print(\"Error: Could not read the mol file.\")\n",
139+
" else: \n",
140+
" xyz_string = obConversion.WriteString(test_mol)\n",
141+
" \n",
142+
" complex_mol = mol3D()\n",
143+
" complex_mol.readfromstring(xyz_string)\n",
144+
" \n",
145+
" geo_dict = complex_mol.get_geometry_type()\n",
146+
" if \"geometry\" in geo_dict:\n",
147+
" print(geo_dict[\"geometry\"])\n",
148+
" except Exception as ex:\n",
149+
" # pass\n",
150+
" print(\"error\", str(ex))\n",
151+
" \n"
152+
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": null,
83157
"id": "55927958",
84158
"metadata": {},
85159
"outputs": [
@@ -103,6 +177,8 @@
103177
}
104178
],
105179
"source": [
180+
"#works only with mol v2\n",
181+
"\n",
106182
"directory = './data'\n",
107183
"\n",
108184
"absolute_file_paths = [os.path.abspath(os.path.join(directory, f)) for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f)) and \"mol\" in f and not \"xyz\" in f]\n",
@@ -121,6 +197,16 @@
121197
" except Exception as ex:\n",
122198
" print(\"error\", str(ex))"
123199
]
200+
},
201+
{
202+
"cell_type": "code",
203+
"execution_count": null,
204+
"id": "facfae74",
205+
"metadata": {},
206+
"outputs": [],
207+
"source": [
208+
"\n"
209+
]
124210
}
125211
],
126212
"metadata": {

0 commit comments

Comments
 (0)