Hi Peter,
Thanks for your input and correction. However, I don't see how the Structure object is updated with the new positions. The simulation context is being updated, but I don't think that is being passed to Structure. I tested your suggestion with the code below:
Code: Select all
top = 'ala.c36.psf'
coord = 'ala.c36.crd'
traj = '100frames.dcd'
psf = CharmmPsfFile(top)
crd = CharmmCrdFile(coord)
box = 2.9*nanometer #
psf.setBox(box,box,box)
system = psf.createSystem(charmm_params, nonbondedMethod=PME, nonbondedCutoff=1.2*nanometers, switchDistance=1.0*nanometer, ewaldErrorTolerance = 0.0005, constraints=HBonds)
integrator = LangevinIntegrator(298, 1/picosecond, 0.002)
simulation = Simulation(psf.topology, system, integrator)
simulation.context.setPositions(crd.positions)
#####
# Initial evaluation
state = simulation.context.getState(getEnergy=True)
potenergy = state.getPotentialEnergy().value_in_unit(kilojoules_per_mole)
energies = pmd.openmm.energy_decomposition_system(stru, system)
totalpotenergy_array = []
for term, energy in energies:
energy = energy*4.184
totalpotenergy_array.append(energy)
totalpotenergy = np.sum(totalpotenergy_array)
print("Initial", potenergy,totalpotenergy)
####
# Loop over trajectory
traj = md.load(dcd_file, top=psf_file)
for frame in range(traj.n_frames):
newpositions = traj.xyz[frame]
simulation.context.setPositions(newpositions)
state = simulation.context.getState(getEnergy=True)
potenergy = state.getPotentialEnergy().value_in_unit(kilojoules_per_mole)
energies = pmd.openmm.energy_decomposition_system(stru, system)
totalpotenergy_array = []
for term, energy in energies:
energy = energy*4.184
totalpotenergy_array.append(energy)
totalpotenergy = np.sum(totalpotenergy_array)
print(frame, potenergy, totalpotenergy)
If I run this, what I get is this comparison:
Code: Select all
Initial -29602.05819440112 -29602.055461647367
0 -32901.96444440112 -29602.047649147367
1 -31255.77694440112 -29602.047649147367
2 -30556.41756940112 -29602.063274147367
3 -29760.02694440112 -29602.055705787992
4 -29603.23006940112 -29602.055461647367
5 -29794.88631940112 -29602.055705787992
6 -29388.67538190112 -29602.055705787992
7 -29687.15975690112 -29602.055461647367
8 -29786.55819440112 -29602.063518287992
9 -29441.23006940112 -29602.063274147367
Am I missing something?