Skip to content

Commit afca60b

Browse files
committed
updated mapping code and logger after recent bugfixes ***NO_CI***
1 parent 5bf5e6b commit afca60b

2 files changed

Lines changed: 68 additions & 43 deletions

File tree

nodes/playground/prepareFEP.ipynb

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,22 @@
3838
" \"\"\" Human readable report on atoms used for the mapping.\"\"\"\n",
3939
" atoms_in_A = list(mapping.keys())\n",
4040
" stream = open('somd.mapping','w')\n",
41+
" atAdone = []\n",
42+
" atBdone= []\n",
4143
" for atAidx in atoms_in_A:\n",
4244
" atA = ligA._sire_molecule.select(atAidx)\n",
4345
" atB = ligB._sire_molecule.select(mapping[atAidx])\n",
44-
" stream.write(\"%s --> %s\\n\" % (atA.name(),atB.name()))\n",
46+
" stream.write(\"%s %s --> %s %s\\n\" % (atA.index(), atA.name(),atB.index(), atB.name()))\n",
47+
" atAdone.append(atA)\n",
48+
" atBdone.append(atB)\n",
49+
" for atom in ligA._sire_molecule.atoms():\n",
50+
" if atom in atAdone:\n",
51+
" continue\n",
52+
" stream.write(\"%s %s --> dummy\\n\" % (atom.index(), atom.name()))\n",
53+
" for atom in ligB._sire_molecule.atoms():\n",
54+
" if atom in atBdone:\n",
55+
" continue\n",
56+
" stream.write(\"dummy --> %s %s\\n\" % (atom.index(), atom.name()))\n",
4557
" stream.close()"
4658
]
4759
},
@@ -72,7 +84,7 @@
7284
"source": [
7385
"node.addInput(\"input1\", BSS.Gateway.FileSet(help=\"A topology and coordinates file\"))\n",
7486
"node.addInput(\"input2\", BSS.Gateway.FileSet(help=\"A topology and coordinates file\"))\n",
75-
"node.addInput(\"prematch\", BSS.Gateway.String(help=\"list of atom indices that are matched between input1 and input2. Syntax is of the format 1-3,4-8,9-11...\", default=\"\"))\n",
87+
"node.addInput(\"prematch\", BSS.Gateway.String(help=\"list of atom indices that are matched between input2 and input1. Syntax is of the format 1-3,4-8,9-11...\", default=\"\"))\n",
7688
"node.addInput(\"output\", BSS.Gateway.String(help=\"The root name for the files describing the perturbation input1->input2.\"))"
7789
]
7890
},
@@ -103,11 +115,12 @@
103115
"# Optional input, dictionary of Atom indices that should be matched in the search. \n",
104116
"prematch = {}\n",
105117
"prematchstring = node.getInput(\"prematch\")\n",
106-
"entries = prematchstring.split(\",\")\n",
107-
"for entry in entries:\n",
108-
" idxA, idxB = entry.split(\"-\")\n",
109-
" prematch[ AtomIdx( int(idxA)) ] = AtomIdx( int(idxB) )\n",
110-
"print (prematch)"
118+
"if len(prematchstring) > 0: \n",
119+
" entries = prematchstring.split(\",\")\n",
120+
" for entry in entries:\n",
121+
" idxA, idxB = entry.split(\"-\")\n",
122+
" prematch[ AtomIdx( int(idxA)) ] = AtomIdx( int(idxB) )\n",
123+
"#print (prematch)"
111124
]
112125
},
113126
{
@@ -148,22 +161,11 @@
148161
"outputs": [],
149162
"source": [
150163
"# Return a maximum of 10 matches, scored by RMSD and sorted from best to worst.\n",
151-
"mappings = BSS.Align.matchAtoms(lig1, lig2, matches=10, prematch=prematch)\n",
164+
"mappings = BSS.Align.matchAtoms(lig1, lig2, matches=10, prematch=prematch, scoring_function=\"RMSD\", timeout=1*BSS.Units.Time.minute)\n",
152165
"# We retain the top mapping\n",
153166
"mapping = mappings[0]\n",
154-
"print (len(mappings))\n",
155-
"print (mappings)"
156-
]
157-
},
158-
{
159-
"cell_type": "code",
160-
"execution_count": null,
161-
"metadata": {},
162-
"outputs": [],
163-
"source": [
164-
"for x in range(0,len(mappings)):\n",
165-
" print (mappings[x])\n",
166-
" print (\"-----------\")"
167+
"#print (len(mappings))\n",
168+
"#print (mappings)"
167169
]
168170
},
169171
{
@@ -267,7 +269,7 @@
267269
"name": "python",
268270
"nbconvert_exporter": "python",
269271
"pygments_lexer": "ipython3",
270-
"version": "3.5.5"
272+
"version": "3.7.1"
271273
}
272274
},
273275
"nbformat": 4,

nodes/playground/prepareFEP.py

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
#!/usr/bin/env python
22
# coding: utf-8
33

44
# Author: Julien Michel
@@ -8,72 +8,86 @@
88
# # PrepareFEP
99
# Loads a pair of input files, perform mapping between the first molecule of each input. Write down input files for a SOMD FEP calculation.
1010

11-
# In[8]:
11+
# In[1]:
1212

1313

1414
import BioSimSpace as BSS
1515
import os
1616
from Sire.Mol import AtomIdx
1717

1818

19-
# In[9]:
19+
# In[2]:
2020

2121

2222
def writeLog(ligA, ligB, mapping):
2323
""" Human readable report on atoms used for the mapping."""
2424
atoms_in_A = list(mapping.keys())
2525
stream = open('somd.mapping','w')
26+
atAdone = []
27+
atBdone= []
2628
for atAidx in atoms_in_A:
2729
atA = ligA._sire_molecule.select(atAidx)
2830
atB = ligB._sire_molecule.select(mapping[atAidx])
29-
stream.write("%s --> %s\n" % (atA.name(),atB.name()))
31+
stream.write("%s %s --> %s %s\n" % (atA.index(), atA.name(),atB.index(), atB.name()))
32+
atAdone.append(atA)
33+
atBdone.append(atB)
34+
for atom in ligA._sire_molecule.atoms():
35+
if atom in atAdone:
36+
continue
37+
stream.write("%s %s --> dummy\n" % (atom.index(), atom.name()))
38+
for atom in ligB._sire_molecule.atoms():
39+
if atom in atBdone:
40+
continue
41+
stream.write("dummy --> %s %s\n" % (atom.index(), atom.name()))
3042
stream.close()
3143

3244

33-
# In[10]:
45+
# In[3]:
3446

3547

3648
node = BSS.Gateway.Node("A node to generate input files for a SOMD relative free energy calculation.")
3749

3850

39-
# In[11]:
51+
# In[4]:
4052

4153

4254
node.addAuthor(name="Julien Michel", email="julien.michel@ed.ac.uk", affiliation="University of Edinburgh")
4355
node.setLicense("GPLv3")
4456

4557

46-
# In[12]:
58+
# In[5]:
4759

4860

4961
node.addInput("input1", BSS.Gateway.FileSet(help="A topology and coordinates file"))
5062
node.addInput("input2", BSS.Gateway.FileSet(help="A topology and coordinates file"))
51-
node.addInput("prematch", BSS.Gateway.String(help="list of atom indices that are matched between input1 and input2. Syntax is of the format 1-3,4-8,9-11...", default=""))
63+
node.addInput("prematch", BSS.Gateway.String(help="list of atom indices that are matched between input2 and input1. Syntax is of the format 1-3,4-8,9-11...", default=""))
5264
node.addInput("output", BSS.Gateway.String(help="The root name for the files describing the perturbation input1->input2."))
5365

5466

55-
# In[13]:
67+
# In[6]:
5668

5769

5870
node.addOutput("nodeoutput", BSS.Gateway.FileSet(help="SOMD input files for a perturbation of input1->input2."))
5971

6072

61-
# In[14]:
73+
# In[7]:
6274

6375

6476
node.showControls()
6577

6678

67-
# In[17]:
79+
# In[21]:
6880

6981

7082
# Optional input, dictionary of Atom indices that should be matched in the search.
7183
prematch = {}
7284
prematchstring = node.getInput("prematch")
73-
entries = prematchstring.split(",")
74-
for entry in entries:
75-
idxA, idxB = entry.split("-")
76-
prematch[ AtomIdx( int(idxA)) ] = AtomIdx( int(idxB) )
85+
if len(prematchstring) > 0:
86+
entries = prematchstring.split(",")
87+
for entry in entries:
88+
idxA, idxB = entry.split("-")
89+
prematch[ AtomIdx( int(idxA)) ] = AtomIdx( int(idxB) )
90+
#print (prematch)
7791

7892

7993
# In[9]:
@@ -102,9 +116,12 @@ def writeLog(ligA, ligB, mapping):
102116

103117

104118
# Return a maximum of 10 matches, scored by RMSD and sorted from best to worst.
105-
mappings = BSS.Align.matchAtoms(lig1, lig2, matches=10, prematch=prematch)
119+
mappings = BSS.Align.matchAtoms(lig1, lig2, matches=10, prematch=prematch, scoring_function="RMSD", timeout=1*BSS.Units.Time.minute)
106120
# We retain the top mapping
107121
mapping = mappings[0]
122+
#print (len(mappings))
123+
#print (mappings)
124+
108125

109126
# In[13]:
110127

@@ -120,7 +137,7 @@ def writeLog(ligA, ligB, mapping):
120137
system1.addMolecules(merged)
121138

122139

123-
# In[16]:
140+
# In[14]:
124141

125142

126143
# Log the mapping used
@@ -134,7 +151,7 @@ def writeLog(ligA, ligB, mapping):
134151
os.system(cmd)
135152

136153

137-
# In[20]:
154+
# In[15]:
138155

139156

140157
root = node.getInput("output")
@@ -145,22 +162,28 @@ def writeLog(ligA, ligB, mapping):
145162
mapping = "%s.mapping" % root
146163

147164

148-
# In[21]:
165+
# In[16]:
149166

150167

151168
cmd = "mv merged_at_lam0.pdb %s ; mv somd.pert %s ; mv somd.prm7 %s ; mv somd.rst7 %s ; mv somd.mapping %s ; rm somd.zip ; rm somd.cfg ; rm somd.err; rm somd.out" % (mergedpdb,pert,prm7,rst7,mapping)
152169
#print (cmd)
153170
os.system(cmd)
154171

155172

156-
# In[23]:
173+
# In[17]:
157174

158175

159176
node.setOutput("nodeoutput",[mergedpdb, pert, prm7, rst7, mapping])
160177

161178

162-
# In[24]:
179+
# In[18]:
163180

164181

165182
node.validate()
166183

184+
185+
# In[ ]:
186+
187+
188+
189+

0 commit comments

Comments
 (0)