-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftdmp-prepare-monomer
executable file
·263 lines (222 loc) · 6.63 KB
/
ftdmp-prepare-monomer
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/bash
function print_help_and_exit
{
cat >&2 << 'EOF'
'ftdmp-prepare-monomer' prepares a monomer structure for docking with 'ftdmp-dock'
Options:
--input string * input file path
--output string * output file path for full monomer
--restrict-input string query to restrict input atoms, default is '[]'
--rename-chain string chain name to set or chain renaming rule to apply, default is ''
--randomize flag to center and pseudo-randomly spin the structure
--random-seed number seed for pseudo-random spinning, default is 1, 0 means current time
--forcefield string forcefield name to make structure ready for relaxation, default is ''
--conda-path string conda installation path needed to prepare for relaxation, default is ''
--conda-env string conda environment name needed to prepare for relaxation, default is ''
--help | -h flag to display help message and exit
Examples:
ftdmp-prepare-monomer --input input/model.pdb --output output/prepared_model
ftdmp-prepare-monomer --input input/model.pdb --output output/prepared_model --restrict-input '[-chain A]' \
--randomize --forcefield --conda-path ~/anaconda3 --conda-env alphafold2
EOF
exit 1
}
if [ -z "$1" ]
then
print_help_and_exit
fi
if [ -z "$FTDMPDIR" ]
then
export FTDMPDIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
export PATH="${FTDMPDIR}/core/voronota/expansion_js:${FTDMPDIR}:${PATH}"
fi
command -v voronota-js &> /dev/null || { echo >&2 "Error: 'voronota-js' executable not in binaries path"; exit 1; }
INFILE=""
OUTFILE=""
OUTFILE_FOR_FTDOCK=""
RESTRICT_INPUT="[]"
RENAME_CHAINS=""
RANDOM_SEED="1"
FORCEFIELD=""
CONDA_PATH=""
CONDA_ENV=""
RANDOMIZE="false"
HELP_MODE="false"
while [[ $# > 0 ]]
do
OPTION="$1"
OPTARG="$2"
shift
case $OPTION in
--input)
INFILE="$OPTARG"
shift
;;
--output)
OUTFILE="$OPTARG"
shift
;;
--output-for-ftdock)
OUTFILE_FOR_FTDOCK="$OPTARG"
shift
;;
--restrict-input)
RESTRICT_INPUT="$OPTARG"
shift
;;
--rename-chain)
RENAME_CHAINS="$OPTARG"
shift
;;
--random-seed)
RANDOM_SEED="$OPTARG"
shift
;;
--forcefield)
FORCEFIELD="$OPTARG"
shift
;;
--conda-path)
CONDA_PATH="$OPTARG"
shift
;;
--conda-env)
CONDA_ENV="$OPTARG"
shift
;;
--randomize)
RANDOMIZE="true"
;;
-h|--help)
HELP_MODE="true"
;;
*)
echo >&2 "Error: invalid command line option '$OPTION'"
exit 1
;;
esac
done
if [ "$HELP_MODE" == "true" ]
then
print_help_and_exit
fi
if [ -z "$INFILE" ]
then
echo >&2 "Error: input file path not provided"
exit 1
fi
if [ -z "$OUTFILE" ] && [ -z "$OUTFILE_FOR_FTDOCK" ]
then
echo >&2 "Error: output file path not provided"
exit 1
fi
if [ ! -s "$INFILE" ]
then
echo >&2 "Error: input file '$INFILE' does not exist"
exit 1
fi
if [ -n "$FORCEFIELD" ] && [ "$FORCEFIELD" != "amber99sb" ] && [ "$FORCEFIELD" != "amber14-all" ] && [ "$FORCEFIELD" != "amber14-all-no-water" ] && [ "$FORCEFIELD" != "charmm36" ]
then
echo >&2 "Error: invalid forcefield name '$FORCEFIELD'"
exit 1
fi
readonly TMPLDIR=$(mktemp -d)
trap "rm -r $TMPLDIR" EXIT
if [ "$RESTRICT_INPUT" != "[]" ] || [ "$RANDOMIZE" == "true" ]
then
{
cat << EOF
params={}
params.input_file='$INFILE';
params.output_file='$TMPLDIR/structure_stage1.pdb';
params.restrict_input_atoms='$RESTRICT_INPUT';
params.rename_chains='$RENAME_CHAINS';
params.random_seed='$RANDOM_SEED';
params.randomize='$RANDOMIZE';
EOF
cat << 'EOF'
voronota_import("-file", params.input_file, "-include-heteroatoms", "-include-hydrogens");
voronota_assert_partial_success("Failed to import file");
voronota_restrict_atoms("-use", params.restrict_input_atoms);
voronota_assert_full_success("Failed to restrict input atoms by the input query");
if(params.rename_chains)
{
voronota_set_chain_name('-chain-name', params.rename_chains);
voronota_assert_full_success("Failed to rename chains");
}
if(params.randomize==="true")
{
voronota_center_atoms("-use", "[-non-hydrogen]", "-mean-for-origin");
voronota_assert_full_success("Failed to center atoms");
voronota_setup_random_seed("-seed", params.random_seed);
voronota_assert_full_success("Failed to setup random seed");
voronota_move_atoms("-rotate-randomly");
voronota_assert_full_success("Failed to randomly rotate atoms");
}
voronota_export_atoms("-file", params.output_file, "-as-pdb");
voronota_assert_full_success("Failed to export atoms");
EOF
} | voronota-js --no-setup-defaults
if [ ! -s "$TMPLDIR/structure_stage1.pdb" ]
then
echo >&2 "Error: failed stage 1 of structure preparation"
exit 1
fi
else
cat "$INFILE" > "$TMPLDIR/structure_stage1.pdb"
fi
if [ -n "$FORCEFIELD" ]
then
ftdmp-relax-with-openmm \
--conda-path "$CONDA_PATH" \
--conda-env "$CONDA_ENV" \
--no-simulation \
--forcefield "$FORCEFIELD" \
--trim-output \
--input "$TMPLDIR/structure_stage1.pdb" \
--output "$TMPLDIR/structure_stage2.pdb"
if [ ! -s "$TMPLDIR/structure_stage2.pdb" ]
then
echo >&2 "Error: failed stage 2 of structure preparation"
exit 1
fi
else
mv "$TMPLDIR/structure_stage1.pdb" "$TMPLDIR/structure_stage2.pdb"
fi
{
cat << EOF
params={}
params.input_file='$TMPLDIR/structure_stage2.pdb';
params.output_file_full='$TMPLDIR/structure_stage3a.pdb';
params.output_file_for_ftdock='$TMPLDIR/structure_stage3b.pdb';
EOF
cat << 'EOF'
voronota_import("-file", params.input_file, "-include-heteroatoms", "-include-hydrogens");
voronota_assert_partial_success("Failed to import file");
voronota_center_atoms("-use", "[-non-hydrogen]", "-mean-for-origin");
voronota_assert_full_success("Failed to center atoms");
voronota_export_atoms("-file", params.output_file_full, "-as-pdb");
voronota_assert_full_success("Failed to export atoms");
voronota_delete_tags_of_atoms("-tags", "het");
voronota_assert_full_success("Failed to set all heteroatoms as ordinary atoms");
voronota_restrict_atoms("-use", "[-non-hydrogen]");
voronota_assert_full_success("Failed to restrict atoms to non-hydrogen atoms");
voronota_export_atoms("-file", params.output_file_for_ftdock, "-as-pdb");
voronota_assert_full_success("Failed to export atoms");
EOF
} | voronota-js --no-setup-defaults
if [ ! -s "$TMPLDIR/structure_stage3a.pdb" ] || [ ! -s "$TMPLDIR/structure_stage3b.pdb" ]
then
echo >&2 "Error: failed stage 3 of structure preparation"
exit 1
fi
if [ -n "$OUTFILE" ]
then
mkdir -p "$(dirname "$OUTFILE")"
mv "$TMPLDIR/structure_stage3a.pdb" "${OUTFILE}"
fi
if [ -n "$OUTFILE_FOR_FTDOCK" ]
then
mkdir -p "$(dirname "$OUTFILE_FOR_FTDOCK")"
mv "$TMPLDIR/structure_stage3b.pdb" "${OUTFILE_FOR_FTDOCK}"
fi