|
159 | 159 | " BSS.Gateway.String(\n", |
160 | 160 | " help=\"The root name for the files describing the perturbation input1->input2.\"\n", |
161 | 161 | " ),\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", |
169 | 162 | ")" |
170 | 163 | ] |
171 | 164 | }, |
|
198 | 191 | "source": [ |
199 | 192 | "do_mapping = True\n", |
200 | 193 | "custom_mapping = node.getInput(\"mapping\")\n", |
201 | | - "# print (custom_mapping)\n", |
202 | 194 | "if custom_mapping is not None:\n", |
203 | 195 | " do_mapping = False\n", |
204 | | - " mapping = loadMapping(custom_mapping)\n", |
205 | | - " # print (mapping)" |
| 196 | + " mapping = loadMapping(custom_mapping)" |
206 | 197 | ] |
207 | 198 | }, |
208 | 199 | { |
|
218 | 209 | " entries = prematchstring.split(\",\")\n", |
219 | 210 | " for entry in entries:\n", |
220 | 211 | " idxA, idxB = entry.split(\"-\")\n", |
221 | | - " prematch[int(idxA)] = int(idxB)\n", |
222 | | - "# print (prematch)" |
| 212 | + " prematch[int(idxA)] = int(idxB)" |
223 | 213 | ] |
224 | 214 | }, |
225 | 215 | { |
|
270 | 260 | " scoring_function=\"RMSDalign\",\n", |
271 | 261 | " timeout=node.getInput(\"timeout\"),\n", |
272 | 262 | " )\n", |
| 263 | + " \n", |
273 | 264 | " # 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]" |
288 | 266 | ] |
289 | 267 | }, |
290 | 268 | { |
|
293 | 271 | "metadata": {}, |
294 | 272 | "outputs": [], |
295 | 273 | "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()])" |
298 | 275 | ] |
299 | 276 | }, |
300 | 277 | { |
|
307 | 284 | "# on a root mean squared displacement fit to find the optimal translation vector\n", |
308 | 285 | "# (as opposed to merely taking the difference of centroids).\n", |
309 | 286 | "lig2 = BSS.Align.rmsdAlign(lig2, lig1, inverted_mapping)\n", |
| 287 | + "\n", |
310 | 288 | "# Merge the two ligands based on the mapping.\n", |
311 | 289 | "merged = BSS.Align.merge(\n", |
312 | 290 | " lig1,\n", |
|
315 | 293 | " allow_ring_breaking=node.getInput(\"allow_ring_breaking\"),\n", |
316 | 294 | " allow_ring_size_change=node.getInput(\"allow_ring_size_change\"),\n", |
317 | 295 | ")\n", |
| 296 | + "\n", |
318 | 297 | "# Create a composite system\n", |
319 | 298 | "system1.removeMolecules(lig1)\n", |
320 | 299 | "system1.addMolecules(merged)\n", |
| 300 | + "\n", |
321 | 301 | "# Make sure the box vectors are in reduced form.\n", |
322 | 302 | "system1.reduceBoxVectors()\n", |
323 | 303 | "system1.rotateBoxVectors()" |
|
331 | 311 | "source": [ |
332 | 312 | "# Log the mapping used\n", |
333 | 313 | "writeLog(lig1, lig2, mapping)\n", |
334 | | - "# Are we saving output for SOMD2?\n", |
335 | | - "is_somd2 = node.getInput(\"somd2\")\n", |
| 314 | + "\n", |
336 | 315 | "# File root for all output.\n", |
337 | 316 | "root = node.getInput(\"output\")\n", |
| 317 | + "\n", |
| 318 | + "# Save PDB of merged topology.\n", |
338 | 319 | "BSS.IO.saveMolecules(\n", |
339 | 320 | " \"merged_at_lam0.pdb\",\n", |
340 | 321 | " merged,\n", |
|
345 | 326 | " \"element\": \"element0\",\n", |
346 | 327 | " },\n", |
347 | 328 | ")\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" |
360 | 343 | ] |
361 | 344 | }, |
362 | 345 | { |
|
365 | 348 | "metadata": {}, |
366 | 349 | "outputs": [], |
367 | 350 | "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" |
374 | 357 | ] |
375 | 358 | }, |
376 | 359 | { |
|
379 | 362 | "metadata": {}, |
380 | 363 | "outputs": [], |
381 | 364 | "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" |
395 | 379 | ] |
396 | 380 | }, |
397 | 381 | { |
|
400 | 384 | "metadata": {}, |
401 | 385 | "outputs": [], |
402 | 386 | "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", |
407 | 389 | "node.setOutput(\"nodeoutput\", output)" |
408 | 390 | ] |
409 | 391 | }, |
|
413 | 395 | "metadata": {}, |
414 | 396 | "outputs": [], |
415 | 397 | "source": [ |
| 398 | + "# Validate.\n", |
416 | 399 | "node.validate()" |
417 | 400 | ] |
418 | 401 | } |
|
433 | 416 | "name": "python", |
434 | 417 | "nbconvert_exporter": "python", |
435 | 418 | "pygments_lexer": "ipython3", |
436 | | - "version": "3.12.2" |
| 419 | + "version": "3.12.13" |
437 | 420 | } |
438 | 421 | }, |
439 | 422 | "nbformat": 4, |
|
0 commit comments