Closed 1234zou closed 8 months ago
Is the simulation stable? It is possible that the logger is only printing the interaction energy and not the total energy. OpenMM is bio-md code, so it should be working with interaction energies. @jharrymoore Do you have an idea?
Hi, thanks for the issue - @ilyes319 is correct - openMM expects just the interaction energies, so the difference you see is exactly the sum of E0s for the system. Also from a quick look at the temperature it appears something has exploded - could you check whether your minimised structure is visually sensible? I suspect it is, in which case you will need to look at how the potential was fitted. Could you share the log file from the training run?
Make sure that when you do the training, the energies are in eV and distances in Angstrom, and forces are in eV/Angstrom. MACE training only works in those units. Your output shows energies in kJ/mol....
Thank you very much! @ilyes319 and @jharrymoore . The md simulation is not stable (I mean that the temperature is increasing from 62K~1000K during simulation, and there are some unreasonable geometries which have O-O bonds at the end of the simulation). The reason is that the model is very rough currently. I want to utilize the model to run short MD, discard unreasonable structures, perform DFT calculations upon chosen structures (based on model deviation), and finally improve the model. The current explosion is as expected.
Now the problem about energies is solved. The OpenMM prints interaction energies.
I'm sorry that I also have a very related problem: there are mirror molecules in the trajectory. After the md simulation is done, I use the following Python script to convert the .dcd and .pdb files together into a .xyz file:
import mdtraj as md
t = md.load('output.dcd', top='minimised_system.pdb')
t.unitcell_vectors *= 10.0 # nm to A
t.xyz *= 10.0 # nm to A
f = open('output.xyz', 'w+')
for i in range(t.n_frames):
f.write(str(t.n_atoms))
f.write('\nLattice=\"')
f.write(' '.join(map(str,t.unitcell_vectors[i,:,:].flatten())))
f.write('\" Properties=species:S:1:pos:R:3 pbc="T T T"\n')
for j in range(t.n_atoms):
f.write(t.topology.atom(j).element.symbol+' ')
f.write(' '.join(format(x,'.8f') for x in t.xyz[i,j,:]))
f.write('\n')
f.close()
I find that for some snapshots, some water molecules run out of the box (which may be normal), but this water molecule is exactly at the position of a water molecule inside of the box (they just differ by one lacttice vector length). If I use this snapshot to perform PBC-DFT calculation, it will complain about there are two atoms whose distance is zero. Is there something about wrap/unwrap missing in my python script?
Thanks again for your kind help.
@gabor1 , thanks for your kind remind. I do use the energy (in eV) and forces (in eV/A) during training. Here are the first few lines of my training set
1
Lattice="50.0 0.0 0.0 0.0 50.0 0.0 0.0 0.0 50.0" Properties=species:S:1:pos:R:3:forces:R:3 config_type=IsolatedAtom energy=-13.595241664 pbc="F F F"
H 0.0 0.0 0.0 0.0 0.0 0.0
1
Lattice="50.0 0.0 0.0 0.0 50.0 0.0 0.0 0.0 50.0" Properties=species:S:1:pos:R:3:forces:R:3 config_type=IsolatedAtom energy=-2041.115929518 pbc="F F F"
O 0.0 0.0 0.0 0.0 0.0 0.0
192
Lattice="12.420 .000 .000 .000 12.420 .000 .000 .000 12.420" Properties=species:S:1:pos:R:3:forces:R:3 energy=-133048.85539372 stress="-.0026950 .0026167 .0018380 .0026167 -.0082802 .0030255 .0018380 .0030255 -.0071386" pbc="T T T"
O 0.58046800 1.63077000 4.91045700 1.77785023 1.87039867 1.79609273
...
and here are the final few lines of training output
2024-04-05 00:24:42.487 INFO: Evaluating train ...
2024-04-05 00:24:53.382 INFO: Evaluating valid ...
2024-04-05 00:24:53.884 INFO:
+-------------+---------------------+------------------+-------------------+---------------------------------------+
| config_type | RMSE E / meV / atom | RMSE F / meV / A | relative F RMSE % | RMSE Stress (Virials) / meV / A (A^3) |
+-------------+---------------------+------------------+-------------------+---------------------------------------+
| train | 1.0 | 69.3 | 5.45 | 10.7 |
| valid | 1.2 | 63.0 | 5.28 | 9.0 |
+-------------+---------------------+------------------+-------------------+---------------------------------------+
2024-04-05 00:24:53.884 INFO: Saving model to checkpoints/h2o_1_run-1000_swa.model
2024-04-05 00:24:53.959 INFO: Done
The output which includes Total Energy (kJ/mole)
is printed by OpenMM and they are interaction energies, not printed by MACE. So I guess it is O.K. Anyway, I want to thank you for your kind remind since I did make this mistake last week, because I usually deal with energies in Hartree.
Make sure that when you do the training, the energies are in eV and distances in Angstrom, and forces are in eV/Angstrom. MACE training only works in those units. Your output shows energies in kJ/mol....
Just to clarify this - openMM uses kJ/mol and nm as internal units, so the writeout here is expected. MACE must be fitted as Gabor outlines above and the conversion is handled internally in the openmm interface
I'm sorry that I also have a very related problem: there are mirror molecules in the trajectory. After the md simulation is done, I use the following Python script to convert the .dcd and .pdb files together into a .xyz file:
import mdtraj as md t = md.load('output.dcd', top='minimised_system.pdb') t.unitcell_vectors *= 10.0 # nm to A t.xyz *= 10.0 # nm to A f = open('output.xyz', 'w+') for i in range(t.n_frames): f.write(str(t.n_atoms)) f.write('\nLattice=\"') f.write(' '.join(map(str,t.unitcell_vectors[i,:,:].flatten()))) f.write('\" Properties=species:S:1:pos:R:3 pbc="T T T"\n') for j in range(t.n_atoms): f.write(t.topology.atom(j).element.symbol+' ') f.write(' '.join(format(x,'.8f') for x in t.xyz[i,j,:])) f.write('\n') f.close()
I find that for some snapshots, some water molecules run out of the box (which may be normal), but this water molecule is exactly at the position of a water molecule inside of the box (they just differ by one lacttice vector length). If I use this snapshot to perform PBC-DFT calculation, it will complain about there are two atoms whose distance is zero. Is there something about wrap/unwrap missing in my python script?
Thanks again for your kind help.
I see you set unwrap=True in your initial script- you need to wrap molecules back into the periodic box before you try to compute anything else. I recommend using the following as a starting point https://docs.mdanalysis.org/1.0.0/documentation_pages/transformations/wrap.html
could you check whether your minimised structure is visually sensible? I suspect it is, in which case you will need to look at how the potential was fitted. Could you share the log file from the training run?
Yes, files are attached minimised_system_and_log.zip
I see you set unwrap=True in your initial script- you need to wrap molecules back into the periodic box before you try to compute anything else. I recommend using the following as a starting point https://docs.mdanalysis.org/1.0.0/documentation_pages/transformations/wrap.html
Just to make it clear: it is O.K. for me to set unwrap=True
, but I need to wrap molecules back into the periodic box, right?
What makes me confused is that even if I set unwrap=False
, there are still mirror water molecules in the converted .xyz file.
Yes, either setting is fine, but will dictate how the trajectory is processed after the fact - if you use unwrap=True
, you will need to wrap molecules back into the box. I am not sure exactly how you are getting two copies of a molecule in your trajectory. I would strongly recommend using MDAnalysis or similar to make sure your trajectory is imaged properly before you proceed.
Dear MACE developers and users, I've trained a rough model for liquid water (using periodic box). If this model is applied to evaluate the energies of geometries in the training set, the obtained energies are good as expected (which is around -133048 eV). But when I use this model to run a short md trajectory, the output is strange:
The energies shown in md are around -65023 kJ/mol, i.e. -673.9 eV, which is far from the energy of a water box (around -133048 eV). I do not know where is wrong during the md simulation. The python script used to run md is
Please see the attached files
h2o_md.xyz
andh2o_md_1.model
h2o_md.zipBy the way, all the computations are performed on CPU since we have very limited GPU resources. Thanks to anyone for any kind help!