def test_step_uncoupled(self): from math import sqrt # test uncoupled V0 = 2.0 V1 = 3.0 uncoupled_matrix = dynq.NonadiabaticMatrix([[V0, 0.0], [0.0, V1]]) # DEBUG #uncoupled_matrix = dynq.NonadiabaticMatrix([[0.0, 0.0], [0.0, 3.0]]) uncoupled = dynq.potentials.MMSTHamiltonian(uncoupled_matrix) uncoupled_topology = dynq.Topology(masses=[], potential=uncoupled) uncoupled_snap = dynq.MMSTSnapshot( coordinates=np.array([]), momenta=np.array([]), electronic_coordinates=np.array([1.0, 1.0]), electronic_momenta=np.array([1.0, 1.0]), topology=uncoupled_topology ) uncoupled_integ = CandyRozmus4MMST(0.01, uncoupled) import dynamiq_engine.features as dynq_f import openpathsampling.engines.features as paths_f uncoupled_integ.prepare([paths_f.coordinates, dynq_f.momenta, dynq_f.electronic_coordinates, dynq_f.electronic_momenta, dynq_f.action]) explicit_T = lambda pes, snap : ( np.dot(snap.momenta, pes.dHdp(snap)) + np.dot(snap.electronic_momenta, pes.electronic_dHdp(snap)) #- pes.H(snap) + pes.V(snap) ) uncoupled_integ.reset(uncoupled_snap) for i in range(10): uncoupled_integ.step(uncoupled, uncoupled_snap, uncoupled_snap) t=0.01*(i+1) ho1 = exact_ho(time=t, omega=2.0, m=1.0/2.0, q0=1.0, p0=1.0) ho2 = exact_ho(time=t, omega=3.0, m=1.0/3.0, q0=1.0, p0=1.0) T = uncoupled.T(uncoupled_snap) V = uncoupled.V(uncoupled_snap) assert_almost_equal(ho1['L'] + ho2['L'] + 0.5*(V0+V1), T-V) # TODO: note that there's some question about the correctness of # the action here. However, we DO have the correct Lagrangian, # and we get the correct action for other HO systems. So it is # possible that the problem is a fundamental issue with this # integration approach for the action. # For future work to test this, the starting point should be #print ho1['S']+ho2['S']+0.5*(V0+V1)*t, uncoupled_snap.action exact_1 = exact_ho(time=0.1, omega=2.0, m=1.0/2.0, q0=1.0, p0=1.0) exact_2 = exact_ho(time=0.1, omega=3.0, m=1.0/3.0, q0=1.0, p0=1.0) predicted_coordinates = [exact_1['q'][0], exact_2['q'][0]] predicted_momenta = [exact_1['p'][0], exact_2['p'][0]] assert_array_almost_equal(uncoupled_snap.electronic_coordinates, np.array(predicted_coordinates)) assert_array_almost_equal(uncoupled_snap.electronic_momenta, np.array(predicted_momenta)) assert_almost_equal(explicit_T(uncoupled, uncoupled_snap), uncoupled.T(uncoupled_snap))
def test_T(self): # Definition of T is $L + V = p * dH/dp - H + V$; test this directly. # Use a lambda rather than nested def because nested def screws with # my in-editor test runner explicit_T = lambda pes, snap : ( np.dot(snap.momenta, pes.dHdp(snap)) + np.dot(snap.electronic_momenta, pes.electronic_dHdp(snap)) - pes.H(snap) + pes.V(snap) ) pes_T = self.tully.T(self.tully_snap) assert_almost_equal(pes_T, explicit_T(self.tully, self.tully_snap)) assert_almost_equal(explicit_T(self.four_state, self.four_state_snap), self.four_state.T(self.four_state_snap))