@@ -1092,3 +1092,161 @@ def test_extension_fails(self):
10921092 len (sub [- 1 ][0 ].trials [0 ].trajectory ),
10931093 len (traj_bad_extension )+ self .dyn .n_frames_max - 1
10941094 )
1095+
1096+
1097+ class testSingleReplicaMinusMover (object ):
1098+ def setup (self ):
1099+ op = CV_Function ("myid" , fcn = lambda snap :
1100+ snap .coordinates [0 ][0 ])
1101+
1102+ volA = CVRangeVolume (op , - 100 , 0.0 )
1103+ volB = CVRangeVolume (op , 1.0 , 100 )
1104+ volX = CVRangeVolume (op , - 100 , 0.25 )
1105+ self .dyn = CalvinistDynamics ([
1106+ # successful move: (backward extension then forward)
1107+ - 0.13 , 0.13 , 0.33 , - 0.11 , - 0.12 , 0.12 , 0.32 , - 0.131 ,
1108+ # never leaves state:
1109+ - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 ,
1110+ - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 ,
1111+ - 0.25 ,
1112+ - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 ,
1113+ - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 , - 0.15 ,
1114+ # goes to other state:
1115+ 1.16 , 1.26 , 1.16 , - 0.16 , 1.16 , 1.26 , 1.16
1116+ ])
1117+ SampleMover .engine = self .dyn
1118+ self .dyn .initialized = True
1119+ self .innermost = paths .TISEnsemble (volA , volB , volX )
1120+ self .minus = paths .MinusInterfaceEnsemble (volA , volX )
1121+ self .mover = SingleReplicaMinusMover (
1122+ minus_ensemble = self .minus ,
1123+ innermost_ensembles = self .innermost
1124+ )
1125+ self .first_segment = [- 0.1 , 0.1 , 0.3 , 0.1 , - 0.15 ]
1126+ self .list_innermost = [- 0.11 , 0.11 , 0.31 , 0.11 , - 0.12 ]
1127+ self .second_segment = [- 0.25 , 0.2 , 0.4 , 0.2 , - 0.2 ]
1128+ init_minus = make_1d_traj (
1129+ coordinates = self .first_segment + [- 0.35 ] + self .second_segment ,
1130+ velocities = [1.0 ]* 11
1131+ )
1132+ self .minus_sample = Sample (
1133+ replica = - 1 ,
1134+ trajectory = init_minus ,
1135+ ensemble = self .minus
1136+ )
1137+
1138+ def test_is_ensemble_change_mover (self ):
1139+ assert_equal (self .mover .is_ensemble_change_mover , True )
1140+
1141+ def test_successful_move (self ):
1142+ init_innermost = make_1d_traj (self .list_innermost , [1.0 ]* 5 )
1143+ init_sample = Sample (
1144+ replica = 0 ,
1145+ trajectory = init_innermost ,
1146+ ensemble = self .innermost
1147+ )
1148+ gs = SampleSet ([init_sample , self .minus_sample ])
1149+
1150+ extend_forward = self .list_innermost + [0.12 , 0.32 , - 0.131 ]
1151+ extend_backward = [- 0.13 , 0.13 , 0.33 ] + self .list_innermost
1152+
1153+ assert_equal (self .minus (make_1d_traj (extend_forward )), True )
1154+ assert_equal (self .minus (make_1d_traj (extend_backward )), True )
1155+
1156+ output_forward = [- 0.12 , 0.12 , 0.32 , - 0.131 ]
1157+ output_backward = [- 0.13 , 0.13 , 0.33 , - 0.11 ]
1158+
1159+ seg_dir = {}
1160+ for i in range (100 ):
1161+ change = self .mover .move (gs )
1162+ samples = change .results
1163+ sub_samples = change .subchange .subchange .results
1164+ assert_equal (len (samples ), 1 )
1165+ assert_equal (len (sub_samples ), 4 )
1166+ s_inner = [s for s in sub_samples if s .ensemble == self .innermost ]
1167+ s_minus = [s for s in sub_samples if s .ensemble == self .minus ]
1168+ s_seg = [s for s in sub_samples if s .ensemble == self .minus ._segment_ensemble ]
1169+ assert_equal (len (s_inner ), 1 ) # this is the output
1170+ assert_equal (len (s_minus ), 1 ) # this is the minus version
1171+ assert_equal (len (s_seg ), 2 ) # first the selected, then the final
1172+
1173+ for c in change :
1174+ assert_equal (c .accepted , True )
1175+
1176+ assert_equal (change .canonical .mover , self .mover )
1177+
1178+ key = ""
1179+ s_seg0_xvals = [s .coordinates [0 ,0 ] for s in s_seg [0 ].trajectory ]
1180+ if items_equal (s_seg0_xvals , self .list_innermost ):
1181+ key += "0"
1182+ else :
1183+ print "s_seg0_xvals:" , s_seg0_xvals
1184+ raise RuntimeError ("Chosen segment neither first nor last!" )
1185+
1186+ # s_minus is the intermediate
1187+ s_minus_xvals = [s .coordinates [0 ,0 ] for s in s_minus [- 1 ].trajectory ]
1188+ if items_equal (s_minus_xvals , extend_forward ):
1189+ key += "f"
1190+ assert_equal (
1191+ [s .coordinates [0 ,0 ] for s in s_inner [0 ].trajectory ],
1192+ output_forward
1193+ )
1194+ elif items_equal (s_minus_xvals , extend_backward ):
1195+ key += "b"
1196+ assert_equal (
1197+ [s .coordinates [0 ,0 ] for s in s_inner [0 ].trajectory ],
1198+ output_backward
1199+ )
1200+ else :
1201+ print "s_minus_xvals:" , s_minus_xvals
1202+ raise RuntimeError ("Unexpected minus extension result!" )
1203+
1204+
1205+ try :
1206+ seg_dir [key ] += 1
1207+ except KeyError :
1208+ seg_dir [key ] = 1
1209+ assert_equal (len (seg_dir .keys ()), 2 )
1210+
1211+ def test_first_hop_fails (self ):
1212+ crossing_traj = make_1d_traj ([- 0.11 , 0.11 , 0.31 , 1.01 ], [1.0 ]* 4 )
1213+ crossing_samp = Sample (replica = 0 , trajectory = crossing_traj ,
1214+ ensemble = self .innermost )
1215+ gs = SampleSet ([crossing_samp ])
1216+ gs .sanity_check ()
1217+
1218+ change = self .mover .move (gs )
1219+ assert_equal (change .accepted , False )
1220+ assert_equal (len (change .results ), 0 )
1221+ sub_trials = change .subchange .subchange .subchange .trials
1222+ assert_equal (len (sub_trials ), 1 )
1223+ assert_equal (sub_trials [0 ].trajectory , crossing_traj )
1224+ assert_equal (sub_trials [0 ].ensemble , self .minus ._segment_ensemble )
1225+
1226+ def test_extension_fails (self ):
1227+ innermost_bad_extension = [- 0.25 , 0.1 , 0.5 , 0.1 , - 0.25 ]
1228+ traj_bad_extension = make_1d_traj (innermost_bad_extension , [1.0 ]* 5 )
1229+ samp_bad_extension = Sample (
1230+ replica = 0 ,
1231+ trajectory = traj_bad_extension ,
1232+ ensemble = self .innermost
1233+ )
1234+
1235+ assert_equal (self .innermost (traj_bad_extension ), True )
1236+
1237+ gs = SampleSet ([self .minus_sample , samp_bad_extension ])
1238+ change = self .mover .move (gs )
1239+ assert_equal (change .accepted , False ) # whole minus has failed
1240+
1241+ # Minus : Filter :ChooseFB : CondSeq
1242+ sub = change .subchange .subchange .subchange
1243+ assert_equal (len (sub .trials ), 2 )
1244+ assert_equal (len (change .trials ), 0 ) # no trials survive filtering
1245+ assert_subchanges_set_accepted (sub , [True , False ])
1246+
1247+ # first two work and the extention fails
1248+ # this only happens due to length
1249+ assert_equal (
1250+ len (sub [- 1 ].trials [0 ].trajectory ),
1251+ len (traj_bad_extension )+ self .dyn .n_frames_max - 1
1252+ )
0 commit comments