Skip to content

Commit 24a9144

Browse files
authored
Merge pull request #516 from OpenBioSim/feature_somd2_preparefep
Write both SOMD1 and SOMD2 input in prepareFEP
2 parents 28a1c27 + 844f7ab commit 24a9144

2 files changed

Lines changed: 95 additions & 125 deletions

File tree

nodes/playground/prepareFEP.ipynb

Lines changed: 49 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,6 @@
159159
" BSS.Gateway.String(\n",
160160
" help=\"The root name for the files describing the perturbation input1->input2.\"\n",
161161
" ),\n",
162-
")\n",
163-
"node.addInput(\n",
164-
" \"somd2\",\n",
165-
" BSS.Gateway.Boolean(\n",
166-
" help=\"Whether to generate input for SOMD2.\",\n",
167-
" default=False,\n",
168-
" ),\n",
169162
")"
170163
]
171164
},
@@ -198,11 +191,9 @@
198191
"source": [
199192
"do_mapping = True\n",
200193
"custom_mapping = node.getInput(\"mapping\")\n",
201-
"# print (custom_mapping)\n",
202194
"if custom_mapping is not None:\n",
203195
" do_mapping = False\n",
204-
" mapping = loadMapping(custom_mapping)\n",
205-
" # print (mapping)"
196+
" mapping = loadMapping(custom_mapping)"
206197
]
207198
},
208199
{
@@ -218,8 +209,7 @@
218209
" entries = prematchstring.split(\",\")\n",
219210
" for entry in entries:\n",
220211
" idxA, idxB = entry.split(\"-\")\n",
221-
" prematch[int(idxA)] = int(idxB)\n",
222-
"# print (prematch)"
212+
" prematch[int(idxA)] = int(idxB)"
223213
]
224214
},
225215
{
@@ -270,21 +260,9 @@
270260
" scoring_function=\"RMSDalign\",\n",
271261
" timeout=node.getInput(\"timeout\"),\n",
272262
" )\n",
263+
" \n",
273264
" # We retain the top mapping\n",
274-
" mapping = mappings[0]\n",
275-
" # print (len(mappings))\n",
276-
" # print (mappings)"
277-
]
278-
},
279-
{
280-
"cell_type": "code",
281-
"execution_count": null,
282-
"metadata": {},
283-
"outputs": [],
284-
"source": [
285-
"# print (mapping)\n",
286-
"# for x in range(0,len(mappings)):\n",
287-
"# print (mappings[x], scores[x])"
265+
" mapping = mappings[0]"
288266
]
289267
},
290268
{
@@ -293,8 +271,7 @@
293271
"metadata": {},
294272
"outputs": [],
295273
"source": [
296-
"inverted_mapping = dict([[v, k] for k, v in mapping.items()])\n",
297-
"# print (inverted_mapping)"
274+
"inverted_mapping = dict([[v, k] for k, v in mapping.items()])"
298275
]
299276
},
300277
{
@@ -307,6 +284,7 @@
307284
"# on a root mean squared displacement fit to find the optimal translation vector\n",
308285
"# (as opposed to merely taking the difference of centroids).\n",
309286
"lig2 = BSS.Align.rmsdAlign(lig2, lig1, inverted_mapping)\n",
287+
"\n",
310288
"# Merge the two ligands based on the mapping.\n",
311289
"merged = BSS.Align.merge(\n",
312290
" lig1,\n",
@@ -315,9 +293,11 @@
315293
" allow_ring_breaking=node.getInput(\"allow_ring_breaking\"),\n",
316294
" allow_ring_size_change=node.getInput(\"allow_ring_size_change\"),\n",
317295
")\n",
296+
"\n",
318297
"# Create a composite system\n",
319298
"system1.removeMolecules(lig1)\n",
320299
"system1.addMolecules(merged)\n",
300+
"\n",
321301
"# Make sure the box vectors are in reduced form.\n",
322302
"system1.reduceBoxVectors()\n",
323303
"system1.rotateBoxVectors()"
@@ -331,10 +311,11 @@
331311
"source": [
332312
"# Log the mapping used\n",
333313
"writeLog(lig1, lig2, mapping)\n",
334-
"# Are we saving output for SOMD2?\n",
335-
"is_somd2 = node.getInput(\"somd2\")\n",
314+
"\n",
336315
"# File root for all output.\n",
337316
"root = node.getInput(\"output\")\n",
317+
"\n",
318+
"# Save PDB of merged topology.\n",
338319
"BSS.IO.saveMolecules(\n",
339320
" \"merged_at_lam0.pdb\",\n",
340321
" merged,\n",
@@ -345,18 +326,20 @@
345326
" \"element\": \"element0\",\n",
346327
" },\n",
347328
")\n",
348-
"if is_somd2:\n",
349-
" BSS.Stream.save(system1, root)\n",
350-
" stream_file = \"%s.bss\" % root\n",
351-
"else:\n",
352-
" # Generate package specific input\n",
353-
" protocol = BSS.Protocol.FreeEnergy(\n",
354-
" runtime=2 * BSS.Units.Time.femtosecond, num_lam=3\n",
355-
" )\n",
356-
" process = BSS.Process.Somd(system1, protocol)\n",
357-
" process.getOutput()\n",
358-
" with zipfile.ZipFile(\"somd_output.zip\", \"r\") as zip_hnd:\n",
359-
" zip_hnd.extractall(\".\")"
329+
"\n",
330+
"\n",
331+
"# Generate SOMD1 input.\n",
332+
"protocol = BSS.Protocol.FreeEnergy(\n",
333+
" runtime=2 * BSS.Units.Time.femtosecond, num_lam=3\n",
334+
")\n",
335+
"process = BSS.Process.Somd(system1, protocol)\n",
336+
"process.getOutput()\n",
337+
"with zipfile.ZipFile(\"somd_output.zip\", \"r\") as zip_hnd:\n",
338+
" zip_hnd.extractall(\".\")\n",
339+
"\n",
340+
"# Generate SOMD2 input.\n",
341+
"BSS.Stream.save(system1, root)\n",
342+
"stream_file = \"%s.bss\" % root"
360343
]
361344
},
362345
{
@@ -365,12 +348,12 @@
365348
"metadata": {},
366349
"outputs": [],
367350
"source": [
368-
"if not is_somd2:\n",
369-
" mergedpdb = \"%s.mergeat0.pdb\" % root\n",
370-
" pert = \"%s.pert\" % root\n",
371-
" prm7 = \"%s.prm7\" % root\n",
372-
" rst7 = \"%s.rst7\" % root\n",
373-
" mapping_str = \"%s.mapping\" % root"
351+
"# Remap ouput names.\n",
352+
"mergedpdb = \"%s.mergeat0.pdb\" % root\n",
353+
"pert = \"%s.pert\" % root\n",
354+
"prm7 = \"%s.prm7\" % root\n",
355+
"rst7 = \"%s.rst7\" % root\n",
356+
"mapping_str = \"%s.mapping\" % root"
374357
]
375358
},
376359
{
@@ -379,19 +362,20 @@
379362
"metadata": {},
380363
"outputs": [],
381364
"source": [
382-
"if not is_somd2:\n",
383-
" os.replace(\"merged_at_lam0.pdb\", mergedpdb)\n",
384-
" os.replace(\"somd.pert\", pert)\n",
385-
" os.replace(\"somd.prm7\", prm7)\n",
386-
" os.replace(\"somd.rst7\", rst7)\n",
387-
" os.replace(\"somd.mapping\", mapping_str)\n",
388-
" try:\n",
389-
" os.remove(\"somd_output.zip\")\n",
390-
" os.remove(\"somd.cfg\")\n",
391-
" os.remove(\"somd.err\")\n",
392-
" os.remove(\"somd.out\")\n",
393-
" except Exception:\n",
394-
" pass"
365+
"# Rename.\n",
366+
"os.replace(\"merged_at_lam0.pdb\", mergedpdb)\n",
367+
"os.replace(\"somd.pert\", pert)\n",
368+
"os.replace(\"somd.prm7\", prm7)\n",
369+
"os.replace(\"somd.rst7\", rst7)\n",
370+
"os.replace(\"somd.mapping\", mapping_str)\n",
371+
"try:\n",
372+
" # Remove redundant files.\n",
373+
" os.remove(\"somd_output.zip\")\n",
374+
" os.remove(\"somd.cfg\")\n",
375+
" os.remove(\"somd.err\")\n",
376+
" os.remove(\"somd.out\")\n",
377+
"except Exception:\n",
378+
" pass"
395379
]
396380
},
397381
{
@@ -400,10 +384,8 @@
400384
"metadata": {},
401385
"outputs": [],
402386
"source": [
403-
"if is_somd2:\n",
404-
" output = [stream_file]\n",
405-
"else:\n",
406-
" output = [mergedpdb, pert, prm7, rst7, mapping_str]\n",
387+
"# Set the node output.\n",
388+
"output = [mergedpdb, pert, prm7, rst7, mapping_str, stream_file]\n",
407389
"node.setOutput(\"nodeoutput\", output)"
408390
]
409391
},
@@ -413,6 +395,7 @@
413395
"metadata": {},
414396
"outputs": [],
415397
"source": [
398+
"# Validate.\n",
416399
"node.validate()"
417400
]
418401
}
@@ -433,7 +416,7 @@
433416
"name": "python",
434417
"nbconvert_exporter": "python",
435418
"pygments_lexer": "ipython3",
436-
"version": "3.12.2"
419+
"version": "3.12.13"
437420
}
438421
},
439422
"nbformat": 4,

0 commit comments

Comments
 (0)