This repository has been archived by the owner on Feb 25, 2022. It is now read-only.
forked from Colvars/colvars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-colvars-code.sh
executable file
·412 lines (360 loc) · 10.6 KB
/
update-colvars-code.sh
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#!/bin/bash
# -*- sh-basic-offset: 2; sh-indentation: 2; -*-
# Script to update a NAMD, VMD, or LAMMPS source tree with the latest Colvars
# version.
# Enforce using portable C locale
LC_ALL=C
export LC_ALL
if [ $# -lt 1 ]
then
cat <<EOF
usage: sh $0 [-f] <target source tree>
-f "force-update": overwrite conflicting files such as Makefile
(default: create diff files for inspection --- MD code may be different)
<target source tree> = root directory of the MD code sources
supported codes: NAMD, VMD, VMD PLUGINS, LAMMPS
EOF
exit 1
fi
# Was the target Makefile changed?
updated_makefile=0
# Was the last file updated?
updated_file=0
force_update=0
if [ $1 = "-f" ]
then
echo "Forcing update of all files"
force_update=1
shift
fi
# Undocumented flag
reverse=0
if [ $1 = "-R" ]
then
echo "Reverse: updating git tree from downstream tree"
reverse=1
shift
fi
# Infer source path from name of script
source=$(dirname "$0")
# Check general validity of target path
target="$1"
if [ ! -d "${target}" ]
then
echo "ERROR: Target directory ${target} does not exist"
exit 2
fi
# Undocumented option to only compare trees
checkonly=0
[ "$2" = "--diff" ] && checkonly=1
[ $force_update = 1 ] && checkonly=0
# Try to determine what code resides inside the target dir
code=unknown
if [ -f "${target}/src/lammps.h" ]
then
code="LAMMPS"
elif [ -f "${target}/src/NamdTypes.h" ]
then
code="NAMD"
elif [ -f "${target}/src/VMDApp.h" ]
then
code="VMD"
elif [ -f "${target}/include/molfile_plugin.h" ]
then
code="VMD-PLUGINS"
elif [ -f "${target}/src/gromacs/commandline.h" ]
then
code="GROMACS"
else
# Handle the case if the user points to ${target}/src
target=$(dirname "${target}")
if [ -f "${target}/src/lammps.h" ]
then
code="LAMMPS"
elif [ -f "${target}/src/NamdTypes.h" ]
then
code="NAMD"
elif [ -f "${target}/src/VMDApp.h" ]
then
code="VMD"
elif [ -f "${target}/src/gromacs/commandline.h" ]
then
code="GROMACS"
else
echo ERROR: Cannot detect a supported code in the target directory
exit 3
fi
fi
echo "Detected ${code} source tree in ${target}"
echo -n "Updating ..."
# Conditional file copy
condcopy() {
if [ $reverse -eq 1 ]
then
a=$2
b=$1
PATCH_OPT="-R"
else
a=$1
b=$2
PATCH_OPT=""
fi
updated_file=0
if [ -d $(dirname "$b") ]
then
if [ $checkonly -eq 1 ]
then
cmp -s "$a" "$b" || diff -uNw "$b" "$a"
else
if ! cmp -s "$a" "$b" ; then
cp "$a" "$b"
updated_file=1
fi
echo -n '.'
fi
fi
}
# Check files related to, but not part of the Colvars module
checkfile() {
if [ $reverse -eq 1 ]
then
a=$2
b=$1
else
a=$1
b=$2
fi
diff -uNw "${a}" "${b}" > $(basename ${a}).diff
if [ -s $(basename ${a}).diff ]
then
echo "Differences found between ${a} and ${b} -- Check $(basename ${a}).diff and merge changes as needed, or use the -f flag."
if [ $force_update = 1 ]
then
echo "Overwriting ${b}, as requested by the -f flag."
cp "$a" "$b"
fi
else
rm -f $(basename ${a}).diff
fi
}
# Update LAMMPS tree
if [ ${code} = "LAMMPS" ]
then
# Update code-independent headers and sources
for src in ${source}/src/*.h ${source}/src/*.cpp
do \
tgt=$(basename ${src})
condcopy "${src}" "${target}/lib/colvars/${tgt}"
done
# Update makefiles for library
for src in ${source}/lammps/lib/colvars/Makefile.{common,deps}
do \
tgt=$(basename ${src})
condcopy "${src}" "${target}/lib/colvars/${tgt}"
done
# Update LAMMPS interface files (package part)
if [ -f ${target}/src/random_park.h ]
then
# GitHub version, using old pseudo random number generators
for src in ${source}/lammps/src/USER-COLVARS/colvarproxy_lammps.cpp \
${source}/lammps/src/USER-COLVARS/colvarproxy_lammps.h \
${source}/lammps/src/USER-COLVARS/colvarproxy_lammps_version.h \
${source}/lammps/src/USER-COLVARS/fix_colvars.cpp \
${source}/lammps/src/USER-COLVARS/fix_colvars.h
do \
tgt=$(basename ${src})
condcopy "${src}" "${target}/src/USER-COLVARS/${tgt}"
done
else
echo "ERROR: Support for the new pRNG (old LAMMPS-ICMS branch) is currently disabled."
exit 2
fi
downloaded_pdf=0
# Copy PDF of the user manual
if [ ! -f ${source}/doc/colvars-refman-lammps.pdf ] ; then
if curl -L -o ${source}/doc/colvars-refman-lammps.pdf \
https://colvars.github.io/pdf/colvars-refman-lammps.pdf \
1> /dev/null 2> /dev/null || \
wget -O ${source}/doc/colvars-refman-lammps.pdf \
https://colvars.github.io/pdf/colvars-refman-lammps.pdf \
1> /dev/null 2> /dev/null \
; then
downloaded_pdf=1
echo -n '.'
else
echo ""
echo "Error: could not download the PDF manual automatically."
echo "Please download it manually from:"
echo " https://colvars.github.io/pdf/colvars-refman-lammps.pdf"
echo "and copy it into ${source}/doc,"
echo "or re-generate it using:"
echo " cd ${source}/doc ; make colvars-refman-lammps.pdf; cd -"
exit 1
fi
fi
for src in ${source}/doc/colvars-refman-lammps.pdf
do \
tgt=$(basename ${src})
condcopy "${src}" "${docdir}/src/PDF/${tgt}"
done
echo ' done.'
if [ ${downloaded_pdf} = 1 ] ; then
echo "Note: the PDF manual for the latest Colvars version was downloaded. "
echo "If you are using an older version, you can generate the corresponding PDF with:"
echo " cd ${source}/doc ; make colvars-refman-lammps.pdf; cd -"
echo "and run this script a second time."
fi
exit 0
fi
# Update NAMD tree
if [ ${code} = "NAMD" ]
then
# New layout: copy library files to the "colvars" folder
for src in ${source}/src/*.h ${source}/src/*.cpp
do \
tgt=$(basename ${src})
condcopy "${src}" "${target}/colvars/src/${tgt}"
done
condcopy "${source}/namd/colvars/src/Makefile.namd" \
"${target}/colvars/src/Makefile.namd"
if [ $updated_file = 1 ] ; then
updated_makefile=1
fi
condcopy "${source}/namd/colvars/Make.depends" \
"${target}/colvars/Make.depends"
# Update abf_integrate
for src in ${source}/colvartools/*h ${source}/colvartools/*cpp
do \
tgt=$(basename ${src})
condcopy "${src}" "${target}/lib/abf_integrate/${tgt}"
done
condcopy "${source}/colvartools/Makefile" \
"${target}/lib/abf_integrate/Makefile"
# Update NAMD interface files
for src in \
${source}/namd/src/colvarproxy_namd.h \
${source}/namd/src/colvarproxy_namd_version.h \
${source}/namd/src/colvarproxy_namd.C
do \
tgt=$(basename ${src})
condcopy "${src}" "${target}/src/${tgt}"
done
# Copy doc files
condcopy "${source}/doc/colvars-refman.bib" \
"${target}/ug/ug_colvars.bib"
condcopy "${source}/doc/colvars-refman-main.tex" \
"${target}/ug/ug_colvars.tex"
condcopy "${source}/doc/cvscript-tcl.tex" \
"${target}/ug/ug_colvars_tclref_namd.tex"
condcopy "${source}/namd/ug/ug_colvars_macros.tex" \
"${target}/ug/ug_colvars_macros.tex"
condcopy "${source}/doc/colvars_diagram.pdf" \
"${target}/ug/figures/colvars_diagram.pdf"
condcopy "${source}/doc/colvars_diagram.eps" \
"${target}/ug/figures/colvars_diagram.eps"
echo ' done.'
# Check for changes in related NAMD files
for src in \
${source}/namd/src/GlobalMasterColvars.h \
${source}/namd/src/ScriptTcl.h \
${source}/namd/src/ScriptTcl.C \
${source}/namd/src/SimParameters.h \
${source}/namd/src/SimParameters.C \
;
do \
tgt=$(basename ${src})
checkfile "${src}" "${target}/src/${tgt}"
done
for src in ${source}/namd/Make* ${source}/namd/config
do
tgt=$(basename ${src})
checkfile "${src}" "${target}/${tgt}"
if [ $updated_file = 1 ] ; then
updated_makefile=1
fi
done
# One last check that each file is correctly included in the dependencies
for file in ${target}/colvars/src/*.{cpp,h} ; do
if [ ! -f ${target}/colvars/Make.depends ] || \
[ ! -f ${target}/lepton/Make.depends ] ; then
updated_makefile=1
break
fi
if ! grep -q ${file} ${target}/colvars/Make.depends ; then
updated_makefile=1
fi
done
if [ $updated_makefile = 1 ] ; then
echo ""
echo " *************************************************"
echo " Please run \"make depends\" in the NAMD tree."
echo " *************************************************"
fi
exit 0
fi
# Update VMD tree
if [ ${code} = "VMD" ]
then
# Update code-independent headers
for src in ${source}/src/*.h
do \
tgt=$(basename ${src})
condcopy "${src}" "${target}/src/${tgt}"
done
# Update code-independent sources
for src in ${source}/src/*.cpp
do \
tgt=$(basename ${src%.cpp})
condcopy "${src}" "${target}/src/${tgt}.C"
done
condcopy "${source}/doc/colvars-refman.bib" \
"${target}/doc/ug_colvars.bib"
condcopy "${source}/doc/colvars-refman-main.tex" \
"${target}/doc/ug_colvars.tex"
condcopy "${source}/doc/cvscript-tcl.tex" \
"${target}/doc/ug_colvars_tclref_vmd.tex"
condcopy "${source}/vmd/doc/ug_colvars_macros.tex" \
"${target}/doc/ug_colvars_macros.tex"
condcopy "${source}/doc/colvars_diagram.pdf" \
"${target}/doc/pictures/colvars_diagram.pdf"
condcopy "${source}/doc/colvars_diagram.eps" \
"${target}/doc/pictures/colvars_diagram.eps"
# Update VMD interface files
for src in \
${source}/vmd/src/colvarproxy_vmd.h \
${source}/vmd/src/colvarproxy_vmd_version.h \
${source}/vmd/src/colvarproxy_vmd.C
do \
tgt=$(basename ${src})
condcopy "${src}" "${target}/src/${tgt}"
done
condcopy "${source}/vmd/src/colvars_files.pl" "${target}/src/colvars_files.pl"
echo ' done.'
exit 0
fi
# Update VMD plugins tree
if [ ${code} = "VMD-PLUGINS" ]
then
# Use the Dashboard's Makefile to patch the plugin tree
if pushd ${source}/vmd/cv_dashboard > /dev/null ; then
DASHBOARD_VERSION=$(grep ^VERSION Makefile.local | cut -d' ' -f 3)
if [ -d ${target}/noarch ] ; then
# This is an already-installed plugin tree
DASHBOARD_DESTINATION=${target}/noarch/tcl/cv_dashboard${DASHBOARD_VERSION}
else
# This is the source tree
DASHBOARD_DESTINATION=${target}/cv_dashboard
fi
DESTINATION=${DASHBOARD_DESTINATION} \
make --quiet -f Makefile.local > /dev/null
echo -n '......'
popd > /dev/null
fi
echo ' done.'
fi
# Update GROMACS tree
if [ ${code} = "GROMACS" ]
then
echo "Error: the GROMACS implementation of Colvars is not under active development."
exit 1
fi