-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdsDNA.Snakefile
More file actions
205 lines (179 loc) · 7.04 KB
/
dsDNA.Snakefile
File metadata and controls
205 lines (179 loc) · 7.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Reference: http://cgmartini.nl/index.php/tutorials-general-introduction-gmx5/tutorial-martini-dna-gmx5
import multiprocessing
thread_count = multiprocessing.cpu_count()
rule download_tutorial:
output:
'na-tutorials/dna-tutorial_20170815.tar'
shell:
'''
wget http://cgmartini.nl/images/stories/tutorial/2017/{output}
tar -xf {output}
'''
rule download_pdb:
output:
'na-tutorials/dna-tutorial/martini-dna/1BNA.pdb'
shell:
'wget -O {output} https://files.rcsb.org/download/1BNA.pdb'
rule remove_water:
input:
pdb = rules.download_pdb.output
output:
pdb = 'na-tutorials/dna-tutorial/martini-dna/1BNA-cleaned.pdb'
shell:
'grep -v HETATM {input.pdb} > {output.pdb}'
rule pdb_to_gro:
input:
pdb = rules.remove_water.output.pdb
output:
gro = 'na-tutorials/dna-tutorial/martini-dna/1BNA-cleaned.gro'
shell:
'gmx editconf -f {input.pdb} -o {output.gro}'
# The martinize script is in python 2. I tried to use 2to3 to convert it to python 3,
# but there were errors when trying to run the resulting python 3 script. Therefore,
# python 2 is used in this step. I use a python 2 conda environment.
# You could also give the full path to a python 2 executable.
rule martinize:
input:
script = 'na-tutorials/dna-tutorial/martini-dna/martinize-dna.py',
gro = rules.pdb_to_gro.output.gro,
output:
top = 'na-tutorials/dna-tutorial/martini-dna/cg-dna.top',
pdb = 'na-tutorials/dna-tutorial/martini-dna/cg-1bna.pdb',
itp = 'na-tutorials/dna-tutorial/martini-dna/Nucleic_A+Nucleic_B.itp'
shell:
'''
source activate bio2
python {input.script} -dnatype ds-stiff -f {input.gro} -o {output.top} -x {output.pdb}
mv -f Nucleic_A+Nucleic_B.itp {output.itp}
source deactivate
sed -i 's|#include "martini.itp"|#include "martini_v2.1-dna.itp"\\n#include "martini_v2.0_ions.itp"|' {output.top}
'''
# This is different than the tutorial text because the
# tutorial only explains how to add regular water molecules.
# Add anti-freeze waters and ions in separate steps using gmx solvate.
# It might be better to use genion or a program like packmol or randomly replace W with WF and NA+
# in the gro file to get a more random initial distribution of WF and NA+.
rule download_water_box:
output:
'na-tutorials/dna-tutorial/martini-dna/water.gro'
shell:
'wget -O {output} http://cgmartini.nl/images/applications/water/water.gro'
rule create_antifreeze_water_box:
input:
gro = rules.download_water_box.output
output:
gro = 'na-tutorials/dna-tutorial/martini-dna/antifreeze_water.gro'
shell:
'''
cat {input.gro} | sed 's|W |WF|' | cat > temp.gro
cat temp.gro | sed 's| W|WF|' | cat > {output.gro}
rm -f temp.gro
'''
rule create_sodium_box:
input:
gro = rules.download_water_box.output
output:
gro = 'na-tutorials/dna-tutorial/martini-dna/sodium.gro'
shell:
'''
cat {input.gro} | sed 's|W |ION|' | cat > temp.gro
cat temp.gro | sed 's| W|NA+|' | cat > {output.gro}
rm -f temp.gro
'''
rule create_simulation_box:
input:
pdb = rules.martinize.output.pdb
output:
gro = 'na-tutorials/dna-tutorial/martini-dna/box.gro'
shell:
'gmx editconf -f {input.pdb} -d 1.2 -bt dodecahedron -o {output.gro}'
rule solvate:
input:
gro_box = rules.create_simulation_box.output.gro,
gro_water = rules.download_water_box.output,
gro_antifreeze = rules.create_antifreeze_water_box.output.gro,
gro_sodium = rules.create_sodium_box.output.gro
output:
gro = 'na-tutorials/dna-tutorial/martini-dna/bw.gro',
shell:
'''
gmx solvate -cp {input.gro_box} -cs {input.gro_water} -o temp1.gro -radius 0.22 -maxsol 1100
gmx solvate -cp temp1.gro -cs {input.gro_antifreeze} -o temp2.gro -radius 0.22 -maxsol 128
gmx solvate -cp temp2.gro -cs {input.gro_sodium} -o {output.gro} -radius 0.22 -maxsol 22
rm -f temp*.gro
'''
# Create a new top file here instead of just appending to original.
rule add_solvent_to_top:
input:
top = rules.martinize.output.top
output:
top = 'na-tutorials/dna-tutorial/martini-dna/cg-dna_solvated.top'
shell:
'''
cp {input.top} {output.top}
printf "\\nW 1100\\nWF 128\\nNA 22\\n" >> {output.top}
'''
rule grompp_em:
input:
mdp = 'na-tutorials/dna-tutorial/martini-dna/em.mdp',
gro = rules.solvate.output.gro,
top = rules.add_solvent_to_top.output.top
output:
tpr = 'na-tutorials/dna-tutorial/martini-dna/01-em.tpr',
shell:
'gmx grompp -f {input.mdp} -c {input.gro} -p {input.top} -o {output.tpr} -maxwarn 1'
rule run_em:
input:
tpr = rules.grompp_em.output.tpr
output:
gro = 'na-tutorials/dna-tutorial/martini-dna/01-em.gro'
params:
nm = str(rules.grompp_em.output.tpr).rstrip('.tpr')
threads: thread_count
shell:
'gmx mdrun -v -deffnm {params.nm}'
rule grompp_equilibrate:
input:
mdp = 'na-tutorials/dna-tutorial/martini-dna/equil.mdp',
gro = rules.run_em.output.gro,
top = rules.add_solvent_to_top.output.top
output:
tpr = 'na-tutorials/dna-tutorial/martini-dna/02-eq.tpr'
shell:
'gmx grompp -f {input.mdp} -c {input.gro} -p {input.top} -o {output.tpr}'
# GROMACS guesses that it can use 12 threads, but this gives an error related to the -rdd option.
# Runs on 10 threads, so use the minimum of the number of threads available and 10.
rule run_equilibrate:
input:
tpr = rules.grompp_equilibrate.output.tpr
output:
gro = 'na-tutorials/dna-tutorial/martini-dna/02-eq.gro',
cpt = 'na-tutorials/dna-tutorial/martini-dna/02-eq.cpt',
params:
nm = str(rules.grompp_equilibrate.output.tpr).rstrip('.tpr'),
nthreads = min(thread_count, 10)
threads: thread_count
shell:
'gmx mdrun -v -deffnm {params.nm} -rdd 2.0 -nt {params.nthreads} -pin on'
# Start from checkpoint file (.cpt) with -t option instead of .gro.
rule grompp_production:
input:
mdp = 'na-tutorials/dna-tutorial/martini-dna/mdrun.mdp',
gro = rules.run_equilibrate.output.gro,
cpt = rules.run_equilibrate.output.cpt,
top = rules.add_solvent_to_top.output.top
output:
tpr = 'na-tutorials/dna-tutorial/martini-dna/03-run.tpr'
shell:
'gmx grompp -f {input.mdp} -c {input.gro} -t {input.cpt} -p {input.top} -o {output.tpr}'
rule run_production:
input:
tpr = rules.grompp_production.output.tpr
output:
gro = 'na-tutorials/dna-tutorial/martini-dna/03-run.gro',
cpt = 'na-tutorials/dna-tutorial/martini-dna/03-run.cpt',
params:
nm = str(rules.grompp_production.output.tpr).rstrip('.tpr'),
nthreads = min(thread_count, 10)
shell:
'gmx mdrun -v -deffnm {params.nm} -rdd 2.0 -nt {params.nthreads} -pin on'