From dad09a02c350276a01066b188cad32400aeecf93 Mon Sep 17 00:00:00 2001
From: Gareth Tribello <gareth.tribello@gmail.com>
Date: Sun, 26 Apr 2015 14:28:44 +0100
Subject: [PATCH] Added regtest for multirmsd

Changes were also needed as this feature was broken as a consequence
of changes in no-buffer branch.  Change to dynamic list deletes
a check that is active when you compile with -DNDEBUG that is not really needed
---
 regtest/basic/rt-multirmsd/COLVAR.reference |   6 +
 regtest/basic/rt-multirmsd/Makefile         |   1 +
 regtest/basic/rt-multirmsd/config           |   4 +
 regtest/basic/rt-multirmsd/deriv.reference  | 271 ++++++++++++++++++++
 regtest/basic/rt-multirmsd/plumed.dat       |  21 ++
 regtest/basic/rt-multirmsd/test0.pdb        |  17 ++
 regtest/basic/rt-multirmsd/test1.pdb        |  17 ++
 regtest/basic/rt-multirmsd/test2.pdb        |  16 ++
 src/colvar/MultiRMSD.cpp                    |   1 -
 src/reference/MultiDomainRMSD.cpp           |  21 +-
 src/reference/ReferenceValuePack.cpp        |   2 +-
 src/tools/DynamicList.h                     |   3 -
 src/tools/PDB.cpp                           |   7 +-
 13 files changed, 368 insertions(+), 19 deletions(-)
 create mode 100644 regtest/basic/rt-multirmsd/COLVAR.reference
 create mode 100644 regtest/basic/rt-multirmsd/Makefile
 create mode 100644 regtest/basic/rt-multirmsd/config
 create mode 100644 regtest/basic/rt-multirmsd/deriv.reference
 create mode 100644 regtest/basic/rt-multirmsd/plumed.dat
 create mode 100644 regtest/basic/rt-multirmsd/test0.pdb
 create mode 100644 regtest/basic/rt-multirmsd/test1.pdb
 create mode 100644 regtest/basic/rt-multirmsd/test2.pdb

diff --git a/regtest/basic/rt-multirmsd/COLVAR.reference b/regtest/basic/rt-multirmsd/COLVAR.reference
new file mode 100644
index 000000000..d78fe5a91
--- /dev/null
+++ b/regtest/basic/rt-multirmsd/COLVAR.reference
@@ -0,0 +1,6 @@
+#! FIELDS time rmsd0 rmsds1 drmsd1
+ 0.000000  1.823  1.852  2.257
+ 0.050000  1.835  1.863  2.254
+ 0.100000  1.837  1.874  2.254
+ 0.150000  1.838  1.888  2.270
+ 0.200000  1.838  1.898  2.293
diff --git a/regtest/basic/rt-multirmsd/Makefile b/regtest/basic/rt-multirmsd/Makefile
new file mode 100644
index 000000000..3703b27ce
--- /dev/null
+++ b/regtest/basic/rt-multirmsd/Makefile
@@ -0,0 +1 @@
+include ../../scripts/test.make
diff --git a/regtest/basic/rt-multirmsd/config b/regtest/basic/rt-multirmsd/config
new file mode 100644
index 000000000..4804b7f2a
--- /dev/null
+++ b/regtest/basic/rt-multirmsd/config
@@ -0,0 +1,4 @@
+type=driver
+# this is to test a different name
+arg="--plumed plumed.dat --trajectory-stride 10 --timestep 0.005 --ixyz trajectory.xyz --dump-forces forces --dump-forces-fmt=%8.4f"
+extra_files="../../trajectories/trajectory.xyz"
diff --git a/regtest/basic/rt-multirmsd/deriv.reference b/regtest/basic/rt-multirmsd/deriv.reference
new file mode 100644
index 000000000..175a5fef5
--- /dev/null
+++ b/regtest/basic/rt-multirmsd/deriv.reference
@@ -0,0 +1,271 @@
+#! FIELDS time parameter rmsd0 rmsds1 drmsd1
+ 0.000000 0   0.0241   0.0690   0.0714
+ 0.000000 1  -0.0212  -0.0468  -0.0636
+ 0.000000 2  -0.0997  -0.0748  -0.1659
+ 0.000000 3  -0.0275  -0.1153  -0.0579
+ 0.000000 4   0.0388   0.0804   0.0692
+ 0.000000 5  -0.1152  -0.1129  -0.0478
+ 0.000000 6   0.0298   0.0463   0.0593
+ 0.000000 7  -0.0281  -0.0337  -0.0605
+ 0.000000 8   0.0342   0.1877   0.0917
+ 0.000000 9   0.0324   0.0242   0.0634
+ 0.000000 10   0.0256  -0.0197   0.0576
+ 0.000000 11  -0.0386  -0.0584  -0.0417
+ 0.000000 12  -0.0471  -0.0094  -0.0687
+ 0.000000 13   0.0287  -0.0196   0.0537
+ 0.000000 14   0.0286  -0.0146   0.0973
+ 0.000000 15  -0.0435  -0.0191  -0.0675
+ 0.000000 16  -0.0226  -0.0722  -0.0563
+ 0.000000 17   0.0622   0.0310   0.0663
+ 0.000000 18   0.0318   0.0155   0.0297
+ 0.000000 19  -0.0212  -0.0734  -0.0507
+ 0.000000 20   0.1286   0.0695   0.0346
+ 0.000000 21  -0.0242  -0.0148  -0.0441
+ 0.000000 22  -0.0570  -0.0355  -0.0699
+ 0.000000 23   0.1321   0.0723   0.0284
+ 0.000000 24   0.0226   0.0245   0.0280
+ 0.000000 25   0.0020   0.0091   0.0054
+ 0.000000 26  -0.1093  -0.0822   0.0337
+ 0.000000 27  -0.0184  -0.0218  -0.0410
+ 0.000000 28   0.0424   0.0456   0.0810
+ 0.000000 29  -0.1152  -0.0829   0.0351
+ 0.000000 30   0.0117   0.0175   0.0239
+ 0.000000 31  -0.0175   0.0128  -0.0066
+ 0.000000 32   0.0006  -0.0013  -0.0192
+ 0.000000 33   0.0263   0.0132   0.0361
+ 0.000000 34   0.0376   0.0559   0.0256
+ 0.000000 35  -0.0589  -0.0375  -0.0977
+ 0.000000 36  -0.0251  -0.0243  -0.0378
+ 0.000000 37   0.0347   0.0561   0.0283
+ 0.000000 38  -0.0002   0.0010  -0.0164
+ 0.000000 39  -0.0178  -0.0218  -0.0331
+ 0.000000 40  -0.0203   0.0171  -0.0065
+ 0.000000 41   0.0463   0.0299  -0.0415
+ 0.000000 42   0.0249   0.0163   0.0382
+ 0.000000 43  -0.0218   0.0237  -0.0067
+ 0.000000 44   0.1046   0.0732   0.0430
+ 0.000000 45  -0.1710  -0.1869  -0.2966
+ 0.000000 46   0.0311   0.0414   0.0722
+ 0.000000 47   0.0459  -0.0597   0.1272
+ 0.000000 48   0.0311   0.1260   0.0722
+ 0.000000 49  -0.2232  -0.5119  -0.6806
+ 0.000000 50   0.3591   0.3565  -0.0881
+ 0.000000 51   0.0459  -0.0398   0.1272
+ 0.000000 52   0.3591   0.3672  -0.0881
+ 0.000000 53  -1.5345  -1.0892  -1.6681
+ 0.050000 0   0.0288   0.0753   0.0809
+ 0.050000 1  -0.0210  -0.0496  -0.0641
+ 0.050000 2  -0.0995  -0.0725  -0.0422
+ 0.050000 3  -0.0265  -0.1180  -0.0575
+ 0.050000 4   0.0398   0.0798   0.0718
+ 0.050000 5  -0.1164  -0.1153  -0.0519
+ 0.050000 6   0.0298   0.0427   0.0601
+ 0.050000 7  -0.0251  -0.0302  -0.0554
+ 0.050000 8   0.0337   0.1878   0.0913
+ 0.050000 9   0.0343   0.0252   0.0677
+ 0.050000 10   0.0245  -0.0201   0.0556
+ 0.050000 11  -0.0392  -0.0590  -0.0433
+ 0.050000 12  -0.0483  -0.0104  -0.0727
+ 0.050000 13   0.0252  -0.0213   0.0470
+ 0.050000 14   0.0286  -0.0146   0.0998
+ 0.050000 15  -0.0474  -0.0223  -0.0785
+ 0.050000 16  -0.0215  -0.0712  -0.0549
+ 0.050000 17   0.0631   0.0310  -0.0537
+ 0.050000 18   0.0293   0.0131   0.0242
+ 0.050000 19  -0.0219  -0.0734  -0.0524
+ 0.050000 20   0.1297   0.0695   0.0353
+ 0.050000 21  -0.0239  -0.0148  -0.0445
+ 0.050000 22  -0.0553  -0.0334  -0.0666
+ 0.050000 23   0.1308   0.0716   0.0275
+ 0.050000 24   0.0196   0.0227   0.0239
+ 0.050000 25   0.0021   0.0096   0.0063
+ 0.050000 26  -0.1103  -0.0833   0.0300
+ 0.050000 27  -0.0173  -0.0204  -0.0391
+ 0.050000 28   0.0414   0.0454   0.0806
+ 0.050000 29  -0.1172  -0.0838   0.0316
+ 0.050000 30   0.0071   0.0150   0.0184
+ 0.050000 31  -0.0212   0.0105  -0.0117
+ 0.050000 32  -0.0014  -0.0029  -0.0227
+ 0.050000 33   0.0253   0.0136   0.0361
+ 0.050000 34   0.0367   0.0552   0.0244
+ 0.050000 35  -0.0548  -0.0347  -0.0921
+ 0.050000 36  -0.0242  -0.0226  -0.0356
+ 0.050000 37   0.0360   0.0569   0.0306
+ 0.050000 38   0.0022   0.0030  -0.0123
+ 0.050000 39  -0.0131  -0.0175  -0.0255
+ 0.050000 40  -0.0202   0.0170  -0.0070
+ 0.050000 41   0.0463   0.0302  -0.0407
+ 0.050000 42   0.0265   0.0186   0.0421
+ 0.050000 43  -0.0195   0.0248  -0.0042
+ 0.050000 44   0.1043   0.0730   0.0434
+ 0.050000 45  -0.1747  -0.1912  -0.3127
+ 0.050000 46   0.0287   0.0303   0.0667
+ 0.050000 47   0.0538  -0.0580   0.0109
+ 0.050000 48   0.0287   0.1181   0.0667
+ 0.050000 49  -0.2165  -0.5115  -0.6699
+ 0.050000 50   0.3507   0.3443  -0.0836
+ 0.050000 51   0.0538  -0.0363   0.0109
+ 0.050000 52   0.3507   0.3538  -0.0836
+ 0.050000 53  -1.5506  -1.0987  -1.6614
+ 0.100000 0   0.0340   0.0849   0.0923
+ 0.100000 1  -0.0194  -0.0474  -0.0602
+ 0.100000 2  -0.0985  -0.0694  -0.0390
+ 0.100000 3  -0.0284  -0.1266  -0.0628
+ 0.100000 4   0.0386   0.0724   0.0685
+ 0.100000 5  -0.1168  -0.1176  -0.0542
+ 0.100000 6   0.0307   0.0417   0.0624
+ 0.100000 7  -0.0215  -0.0250  -0.0489
+ 0.100000 8   0.0341   0.1870   0.0918
+ 0.100000 9   0.0377   0.0262   0.0731
+ 0.100000 10   0.0240  -0.0202   0.0541
+ 0.100000 11  -0.0400  -0.0593  -0.0459
+ 0.100000 12  -0.0502  -0.0121  -0.0781
+ 0.100000 13   0.0233  -0.0218   0.0444
+ 0.100000 14   0.0266  -0.0155   0.0967
+ 0.100000 15  -0.0502  -0.0249  -0.0869
+ 0.100000 16  -0.0229  -0.0715  -0.0579
+ 0.100000 17   0.0651   0.0320  -0.0493
+ 0.100000 18   0.0264   0.0104   0.0178
+ 0.100000 19  -0.0221  -0.0733  -0.0499
+ 0.100000 20   0.1296   0.0688   0.0345
+ 0.100000 21  -0.0207  -0.0117  -0.0391
+ 0.100000 22  -0.0534  -0.0318  -0.0636
+ 0.100000 23   0.1321   0.0721   0.0291
+ 0.100000 24   0.0182   0.0225   0.0230
+ 0.100000 25   0.0031   0.0106   0.0080
+ 0.100000 26  -0.1100  -0.0827   0.0300
+ 0.100000 27  -0.0172  -0.0195  -0.0381
+ 0.100000 28   0.0419   0.0456   0.0225
+ 0.100000 29  -0.1185  -0.0842   0.0293
+ 0.100000 30   0.0074   0.0159   0.0198
+ 0.100000 31  -0.0241   0.0088  -0.0154
+ 0.100000 32  -0.0025  -0.0036  -0.0242
+ 0.100000 33   0.0240   0.0133   0.0350
+ 0.100000 34   0.0340   0.0534   0.0757
+ 0.100000 35  -0.0537  -0.0337  -0.0903
+ 0.100000 36  -0.0271  -0.0238  -0.0392
+ 0.100000 37   0.0343   0.0557   0.0283
+ 0.100000 38   0.0048   0.0049  -0.0079
+ 0.100000 39  -0.0105  -0.0151  -0.0213
+ 0.100000 40  -0.0203   0.0169  -0.0073
+ 0.100000 41   0.0456   0.0297  -0.0413
+ 0.100000 42   0.0260   0.0188   0.0420
+ 0.100000 43  -0.0154   0.0276   0.0018
+ 0.100000 44   0.1023   0.0715   0.0409
+ 0.100000 45  -0.1864  -0.2119  -0.3427
+ 0.100000 46   0.0305   0.0229   0.0187
+ 0.100000 47   0.0609  -0.0585   0.0159
+ 0.100000 48   0.0305   0.1119   0.0187
+ 0.100000 49  -0.2039  -0.4988  -0.6507
+ 0.100000 50   0.3441   0.3297   0.1343
+ 0.100000 51   0.0609  -0.0352   0.0159
+ 0.100000 52   0.3441   0.3396   0.1343
+ 0.100000 53  -1.5538  -1.0985  -1.6526
+ 0.150000 0   0.0387   0.0939   0.1025
+ 0.150000 1  -0.0179  -0.0441  -0.0553
+ 0.150000 2  -0.0965  -0.0648  -0.1572
+ 0.150000 3  -0.0306  -0.1354  -0.0683
+ 0.150000 4   0.0375   0.0644   0.0640
+ 0.150000 5  -0.1176  -0.1223  -0.0572
+ 0.150000 6   0.0319   0.0415   0.0650
+ 0.150000 7  -0.0182  -0.0203  -0.0430
+ 0.150000 8   0.0356   0.1871   0.0936
+ 0.150000 9   0.0415   0.0276   0.0787
+ 0.150000 10   0.0235  -0.0200   0.0513
+ 0.150000 11  -0.0419  -0.0600  -0.0508
+ 0.150000 12  -0.0516  -0.0133  -0.0827
+ 0.150000 13   0.0233  -0.0207   0.0452
+ 0.150000 14   0.0254  -0.0155   0.0944
+ 0.150000 15  -0.0531  -0.0273  -0.0951
+ 0.150000 16  -0.0250  -0.0717  -0.0623
+ 0.150000 17   0.0661   0.0324   0.0772
+ 0.150000 18   0.0232   0.0077   0.0115
+ 0.150000 19  -0.0233  -0.0735  -0.0512
+ 0.150000 20   0.1289   0.0678   0.0329
+ 0.150000 21  -0.0177  -0.0084  -0.0329
+ 0.150000 22  -0.0531  -0.0317  -0.0631
+ 0.150000 23   0.1331   0.0723   0.0301
+ 0.150000 24   0.0183   0.0236   0.0247
+ 0.150000 25   0.0049   0.0115   0.0103
+ 0.150000 26  -0.1086  -0.0808   0.0327
+ 0.150000 27  -0.0173  -0.0188  -0.0370
+ 0.150000 28   0.0423   0.0455   0.0229
+ 0.150000 29  -0.1185  -0.0837   0.0287
+ 0.150000 30   0.0100   0.0182   0.0242
+ 0.150000 31  -0.0259   0.0078  -0.0175
+ 0.150000 32  -0.0027  -0.0032  -0.0234
+ 0.150000 33   0.0232   0.0130   0.0340
+ 0.150000 34   0.0325   0.0522   0.0734
+ 0.150000 35  -0.0546  -0.0339  -0.0911
+ 0.150000 36  -0.0301  -0.0252  -0.0427
+ 0.150000 37   0.0314   0.0535   0.0243
+ 0.150000 38   0.0070   0.0063  -0.0045
+ 0.150000 39  -0.0112  -0.0152  -0.0219
+ 0.150000 40  -0.0194   0.0175  -0.0054
+ 0.150000 41   0.0449   0.0290  -0.0422
+ 0.150000 42   0.0248   0.0180   0.0401
+ 0.150000 43  -0.0127   0.0295   0.0063
+ 0.150000 44   0.0993   0.0694   0.0369
+ 0.150000 45  -0.2038  -0.2394  -0.3816
+ 0.150000 46   0.0311   0.0157   0.0143
+ 0.150000 47   0.0745  -0.0579   0.1885
+ 0.150000 48   0.0311   0.1050   0.0143
+ 0.150000 49  -0.1971  -0.4861  -0.6372
+ 0.150000 50   0.3474   0.3224   0.1391
+ 0.150000 51   0.0745  -0.0341   0.1885
+ 0.150000 52   0.3474   0.3319   0.1391
+ 0.150000 53  -1.5432  -1.0925  -1.6450
+ 0.200000 0   0.0413   0.0982   0.1068
+ 0.200000 1  -0.0182  -0.0461  -0.0553
+ 0.200000 2  -0.0956  -0.0625  -0.1535
+ 0.200000 3  -0.0323  -0.1411  -0.0724
+ 0.200000 4   0.0379   0.0619   0.0632
+ 0.200000 5  -0.1191  -0.1267  -0.0605
+ 0.200000 6   0.0332   0.0429   0.0670
+ 0.200000 7  -0.0154  -0.0159  -0.0380
+ 0.200000 8   0.0373   0.1892   0.0960
+ 0.200000 9   0.0434   0.0282   0.0809
+ 0.200000 10   0.0241  -0.0185   0.0511
+ 0.200000 11  -0.0441  -0.0609  -0.0549
+ 0.200000 12  -0.0520  -0.0138  -0.0840
+ 0.200000 13   0.0250  -0.0183   0.0478
+ 0.200000 14   0.0263  -0.0147   0.0959
+ 0.200000 15  -0.0539  -0.0283  -0.0983
+ 0.200000 16  -0.0281  -0.0723  -0.0689
+ 0.200000 17   0.0663   0.0322   0.0770
+ 0.200000 18   0.0202   0.0053   0.0058
+ 0.200000 19  -0.0252  -0.0734  -0.0507
+ 0.200000 20   0.1290   0.0671   0.0316
+ 0.200000 21  -0.0156  -0.0058  -0.0281
+ 0.200000 22  -0.0532  -0.0327  -0.0643
+ 0.200000 23   0.1335   0.0726   0.0307
+ 0.200000 24   0.0203   0.0257   0.0287
+ 0.200000 25   0.0056   0.0114   0.0109
+ 0.200000 26  -0.1061  -0.0780  -0.0132
+ 0.200000 27  -0.0165  -0.0176  -0.0345
+ 0.200000 28   0.0437   0.0456   0.0242
+ 0.200000 29  -0.1168  -0.0823   0.0304
+ 0.200000 30   0.0131   0.0207   0.0291
+ 0.200000 31  -0.0270   0.0068  -0.0187
+ 0.200000 32  -0.0031  -0.0030  -0.0231
+ 0.200000 33   0.0224   0.0126   0.0328
+ 0.200000 34   0.0319   0.0515   0.0724
+ 0.200000 35  -0.0553  -0.0342  -0.0914
+ 0.200000 36  -0.0333  -0.0270  -0.0464
+ 0.200000 37   0.0289   0.0515   0.0208
+ 0.200000 38   0.0075   0.0062  -0.0045
+ 0.200000 39  -0.0148  -0.0174  -0.0264
+ 0.200000 40  -0.0181   0.0183  -0.0028
+ 0.200000 41   0.0448   0.0286   0.0084
+ 0.200000 42   0.0244   0.0176   0.0391
+ 0.200000 43  -0.0119   0.0301   0.0083
+ 0.200000 44   0.0955   0.0666   0.0311
+ 0.200000 45  -0.2170  -0.2603  -0.4071
+ 0.200000 46   0.0322   0.0147   0.0117
+ 0.200000 47   0.0892  -0.0560   0.2214
+ 0.200000 48   0.0322   0.1039   0.0117
+ 0.200000 49  -0.2016  -0.4799  -0.6402
+ 0.200000 50   0.3564   0.3212   0.1430
+ 0.200000 51   0.0892  -0.0326   0.2214
+ 0.200000 52   0.3564   0.3288   0.1430
+ 0.200000 53  -1.5257  -1.0834  -1.6404
diff --git a/regtest/basic/rt-multirmsd/plumed.dat b/regtest/basic/rt-multirmsd/plumed.dat
new file mode 100644
index 000000000..3b8dc02bd
--- /dev/null
+++ b/regtest/basic/rt-multirmsd/plumed.dat
@@ -0,0 +1,21 @@
+rmsd0:   MULTI-RMSD TYPE=MULTI-OPTIMAL REFERENCE=test0.pdb
+rmsds1:  MULTI-RMSD TYPE=MULTI-SIMPLE  REFERENCE=test1.pdb
+drmsd1:  MULTI-RMSD TYPE=MULTI-DRMSD REFERENCE=test2.pdb 
+
+PRINT ...
+  STRIDE=1
+  ARG=*
+  FILE=COLVAR FMT=%6.3f
+... PRINT
+
+DUMPDERIVATIVES ARG=rmsd0,rmsds1,drmsd1 FILE=deriv FMT=%8.4f
+
+#rmsd0n:   MULTI-RMSD TYPE=MULTI-OPTIMAL REFERENCE=test0.pdb NUMERICAL_DERIVATIVES
+#rmsds1n:  MULTI-RMSD TYPE=MULTI-SIMPLE  REFERENCE=test1.pdb NUMERICAL_DERIVATIVES
+#drmsd1n:  MULTI-RMSD TYPE=MULTI-DRMSD REFERENCE=test2.pdb NUMERICAL_DERIVATIVES
+#
+#DUMPDERIVATIVES ARG=rmsd0,rmsd0n,rmsds1,rmsds1n,drmsd1,drmsd1n FILE=deriv2 FMT=%8.4f
+
+ENDPLUMED
+
+text here should be ignored
diff --git a/regtest/basic/rt-multirmsd/test0.pdb b/regtest/basic/rt-multirmsd/test0.pdb
new file mode 100644
index 000000000..c99361e98
--- /dev/null
+++ b/regtest/basic/rt-multirmsd/test0.pdb
@@ -0,0 +1,17 @@
+ATOM      2  O   ALA     2      -0.926  -2.447  -0.497  1.00  1.00      DIA  O
+ATOM      4  HNT ALA     2       0.533  -0.396   1.184  1.00  1.00      DIA  H
+ATOM      6  HT1 ALA     2      -0.216  -2.590   1.371  1.00  1.00      DIA  H
+ATOM      7  HT2 ALA     2      -0.309  -1.255   2.315  1.00  1.00      DIA  H
+ATOM      8  HT3 ALA     2      -1.480  -1.560   1.212  1.00  1.00      DIA  H
+ATOM      9  CAY ALA     2      -0.096   2.144  -0.669  1.00  1.00      DIA  C
+ATOM     10  HY1 ALA     2       0.871   2.385  -0.588  1.00  1.00      DIA  H
+TER
+ATOM     12  HY3 ALA     2      -0.520   2.679  -1.400  1.00  1.00      DIA  H
+ATOM     14  OY  ALA     2      -1.139   0.931  -0.973  1.00  1.00      DIA  O
+ATOM     16  HN  ALA     2       1.713   1.021  -0.873  1.00  1.00      DIA  H
+ATOM     18  HA  ALA     2       0.099  -0.774  -2.218  1.00  1.00      DIA  H
+ATOM     19  CB  ALA     2       2.063  -1.223  -1.276  1.00  1.00      DIA  C
+ATOM     20  HB1 ALA     2       2.670  -0.716  -2.057  1.00  1.00      DIA  H
+ATOM     21  HB2 ALA     2       2.556  -1.051  -0.295  1.00  1.00      DIA  H
+ATOM     22  HB3 ALA     2       2.070  -2.314  -1.490  1.00  1.00      DIA  H
+TER
diff --git a/regtest/basic/rt-multirmsd/test1.pdb b/regtest/basic/rt-multirmsd/test1.pdb
new file mode 100644
index 000000000..1c044b6a5
--- /dev/null
+++ b/regtest/basic/rt-multirmsd/test1.pdb
@@ -0,0 +1,17 @@
+ATOM      2  O   ALA     2      -0.926  -2.447  -0.497  1.00  1.01      DIA  O
+ATOM      4  HNT ALA     2       0.533  -0.396   1.184  1.00  1.00      DIA  H
+ATOM      6  HT1 ALA     2      -0.216  -2.590   1.371  1.00  1.00      DIA  H
+TER
+ATOM      7  HT2 ALA     2      -0.309  -1.255   2.315  1.00  1.00      DIA  H
+ATOM      8  HT3 ALA     2      -1.480  -1.560   1.212  1.00  1.00      DIA  H
+ATOM      9  CAY ALA     2      -0.096   2.144  -0.669  1.00  1.00      DIA  C
+ATOM     10  HY1 ALA     2       0.871   2.385  -0.588  1.00  1.00      DIA  H
+ATOM     12  HY3 ALA     2      -0.520   2.679  -1.400  1.00  1.00      DIA  H
+ATOM     14  OY  ALA     2      -1.139   0.931  -0.973  1.00  1.00      DIA  O
+ATOM     16  HN  ALA     2       1.713   1.021  -0.873  1.00  1.00      DIA  H
+ATOM     18  HA  ALA     2       0.099  -0.774  -2.218  1.00  1.00      DIA  H
+ATOM     19  CB  ALA     2       2.063  -1.223  -1.276  1.00  0.99      DIA  C
+ATOM     20  HB1 ALA     2       2.670  -0.716  -2.057  1.00  1.00      DIA  H
+ATOM     21  HB2 ALA     2       2.556  -1.051  -0.295  1.00  1.00      DIA  H
+ATOM     22  HB3 ALA     2       2.070  -2.314  -1.490  1.00  1.00      DIA  H
+TER
diff --git a/regtest/basic/rt-multirmsd/test2.pdb b/regtest/basic/rt-multirmsd/test2.pdb
new file mode 100644
index 000000000..c47e6f503
--- /dev/null
+++ b/regtest/basic/rt-multirmsd/test2.pdb
@@ -0,0 +1,16 @@
+ATOM      2  O   ALA     2      -0.926  -2.447  -0.497  1.00  1.00      DIA  O
+ATOM      4  HNT ALA     2       0.533  -0.396   1.184  1.00  1.00      DIA  H
+ATOM      6  HT1 ALA     2      -0.216  -2.590   1.371  1.00  1.00      DIA  H
+ATOM      7  HT2 ALA     2      -0.309  -1.255   2.315  1.00  1.00      DIA  H
+ATOM      8  HT3 ALA     2      -1.480  -1.560   1.212  1.00  1.00      DIA  H
+ATOM      9  CAY ALA     2      -0.096   2.144  -0.669  1.00  1.00      DIA  C
+TER
+ATOM     10  HY1 ALA     2       0.871   2.385  -0.588  1.00  1.00      DIA  H
+ATOM     12  HY3 ALA     2      -0.520   2.679  -1.400  1.00  1.00      DIA  H
+ATOM     14  OY  ALA     2      -1.139   0.931  -0.973  1.00  1.00      DIA  O
+ATOM     16  HN  ALA     2       1.713   1.021  -0.873  1.00  1.00      DIA  H
+ATOM     18  HA  ALA     2       0.099  -0.774  -2.218  1.00  1.00      DIA  H
+ATOM     19  CB  ALA     2       2.063  -1.223  -1.276  1.00  1.00      DIA  C
+ATOM     20  HB1 ALA     2       2.670  -0.716  -2.057  1.00  1.00      DIA  H
+ATOM     21  HB2 ALA     2       2.556  -1.051  -0.295  1.00  1.00      DIA  H
+ATOM     22  HB3 ALA     2       2.070  -2.314  -1.490  1.00  1.00      DIA  H
diff --git a/src/colvar/MultiRMSD.cpp b/src/colvar/MultiRMSD.cpp
index a52aa688e..ecd428f2c 100644
--- a/src/colvar/MultiRMSD.cpp
+++ b/src/colvar/MultiRMSD.cpp
@@ -149,7 +149,6 @@ PLUMED_COLVAR_INIT(ao),squared(false),myvals(1,0), mypack(0,0,myvals)
   
   std::vector<AtomNumber> atoms;
   rmsd->getAtomRequests( atoms );
-//   rmsd->setNumberOfAtoms( atoms.size() );
   requestAtoms( atoms );
 
   myvals.resize( 1, 3*atoms.size()+9 );
diff --git a/src/reference/MultiDomainRMSD.cpp b/src/reference/MultiDomainRMSD.cpp
index 168f7eada..4908d7ce5 100644
--- a/src/reference/MultiDomainRMSD.cpp
+++ b/src/reference/MultiDomainRMSD.cpp
@@ -88,20 +88,19 @@ void MultiDomainRMSD::setReferenceAtoms( const std::vector<Vector>& conf, const
 }
 
 double MultiDomainRMSD::calculate( const std::vector<Vector>& pos, const Pbc& pbc, ReferenceValuePack& myder, const bool& squared ) const {
-  //clearDerivatives(); 
-  double totd=0.; Tensor tvirial; std::vector<Vector> mypos;
-  MultiValue tvals( 1, myder.getNumberOfDerivatives() ); ReferenceValuePack tder( 0, 0, tvals );
+  double totd=0.; Tensor tvirial; std::vector<Vector> mypos; MultiValue tvals( 1, 3*pos.size()+9 ); 
+  ReferenceValuePack tder( 0, getNumberOfAtoms(), tvals ); tder.setValIndex(0);
+
   for(unsigned i=0;i<domains.size();++i){
      // Must extract appropriate positions here
-     mypos.resize( blocks[i+1] - blocks[i] ); 
-     unsigned n=0; tder.resize( 0, mypos.size() );
-     if( pca ) domains[i]->setupPCAStorage( tder );
-     for(unsigned j=blocks[i];j<blocks[i+1];++j){ tder.setAtomIndex(n,j); mypos[n]=pos[j]; n++; }
-
+     mypos.resize( blocks[i+1] - blocks[i] );
+     if( pca ) domains[i]->setupPCAStorage( tder ); 
+     unsigned n=0; for(unsigned j=blocks[i];j<blocks[i+1];++j){ tder.setAtomIndex(n,j); mypos[n]=pos[j]; n++; }
+     for(unsigned k=n;k<getNumberOfAtoms();++k) tder.setAtomIndex(k,pos.size()+1);
      // This actually does the calculation
      totd += weights[i]*domains[i]->calculate( mypos, pbc, tder, true );
      // Now merge the derivative
-     myder.copyScaledDerivatives( 1, weights[i], tvals );
+     myder.copyScaledDerivatives( 0, weights[i], tvals );
      // If PCA copy PCA stuff
      if(pca){
         unsigned n=0;
@@ -118,7 +117,7 @@ double MultiDomainRMSD::calculate( const std::vector<Vector>& pos, const Pbc& pb
      // Make sure virial status is set correctly in output derivative pack
      // This is only done here so I do this by using class friendship
      if( tder.virialWasSet() ) myder.boxWasSet=true;
-     // And clear
+     // Clear the tempory derivatives ready for next loop
      tder.clear();
   }
   if( !squared ){
@@ -185,7 +184,7 @@ double MultiDomainRMSD::projectAtomicDisplacementOnVector( const unsigned& iv, c
       domains[i]->projectAtomicDisplacementOnVector( iv, tvecs, mypos, tder );
      
       // And derivatives
-      mypack.copyScaledDerivatives( 1, weights[i], tvals );
+      mypack.copyScaledDerivatives( 0, weights[i], tvals );
   }
 
   return totd;
diff --git a/src/reference/ReferenceValuePack.cpp b/src/reference/ReferenceValuePack.cpp
index bf4d3eb61..ec319149f 100644
--- a/src/reference/ReferenceValuePack.cpp
+++ b/src/reference/ReferenceValuePack.cpp
@@ -41,7 +41,7 @@ void ReferenceValuePack::updateDynamicLists(){
   for(unsigned i=0;i<numberOfArgs;++i) myvals.putIndexInActiveArray( i );
   for(unsigned i=0;i<atom_indices.size();++i){
      unsigned nbase = numberOfArgs + 3*atom_indices[i];
-     if( myvals.isActive( nbase ) ){
+     if( atom_indices[i]<atom_indices.size() && myvals.isActive( nbase ) ){
         myvals.putIndexInActiveArray( nbase+0 ); myvals.putIndexInActiveArray( nbase+1 ); myvals.putIndexInActiveArray( nbase+2 );
      }
   }
diff --git a/src/tools/DynamicList.h b/src/tools/DynamicList.h
index dce74d156..482cc3b95 100644
--- a/src/tools/DynamicList.h
+++ b/src/tools/DynamicList.h
@@ -277,9 +277,6 @@ void DynamicList<T>::deactivateAll(){
   allWereDeactivated=true; allWereActivated=false;
   for(unsigned i=0;i<nactive;++i) onoff[ active[i] ]= 0; 
   nactive=0;
-#ifndef NDEBUG
-  for(unsigned i=0;i<onoff.size();++i) plumed_dbg_assert( onoff[i]==0 );
-#endif
 }
 
 template <typename T>
diff --git a/src/tools/PDB.cpp b/src/tools/PDB.cpp
index 140980930..be5e34dfd 100644
--- a/src/tools/PDB.cpp
+++ b/src/tools/PDB.cpp
@@ -95,7 +95,7 @@ bool PDB::readFromFilepointer(FILE *fp,bool naturalUnits,double scale){
   bool file_is_alive=false;
   if(naturalUnits) scale=1.0;
   string line;
-  fpos_t pos;
+  fpos_t pos; bool between_ters=true;
   while(Tools::getline(fp,line)){
     //cerr<<line<<"\n";
     fgetpos (fp,&pos);
@@ -112,7 +112,7 @@ bool PDB::readFromFilepointer(FILE *fp,bool naturalUnits,double scale){
     string occ=line.substr(54,6);
     string bet=line.substr(60,6);
     Tools::trim(record);
-    if(record=="TER"){ block_ends.push_back( positions.size() ); }
+    if(record=="TER"){ between_ters=false; block_ends.push_back( positions.size() ); }
     if(record=="END"){ file_is_alive=true;  break;}
     if(record=="ENDMDL"){ file_is_alive=true;  break;}
     if(record=="REMARK"){
@@ -120,6 +120,7 @@ bool PDB::readFromFilepointer(FILE *fp,bool naturalUnits,double scale){
          addRemark( v1 );
     }
     if(record=="ATOM" || record=="HETATM"){
+      between_ters=true;
       AtomNumber a; unsigned resno;
       double o,b;
       Vector p;
@@ -145,7 +146,7 @@ bool PDB::readFromFilepointer(FILE *fp,bool naturalUnits,double scale){
       residuenames.push_back(residuename);
     }
   }
-  block_ends.push_back( positions.size() );
+  if( between_ters ) block_ends.push_back( positions.size() );
   return file_is_alive;
 }
 
-- 
GitLab