New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to handle different units across MD codes? #10
Comments
you could use the system that lammps is using, where it has multiple "unit-sets" that define scaling factors, e.g. to get a force or an energy from positions and masses. for codes (e.g. gromacs. namd) that have their own fixed unit sets, you can identify easily which of the available unit sets is supposed to be used during the initialization of the proxy class, otherwise, it can be communicated. i would consider angles (and dihedrals, impropers) a different thing, since - unlike positions, forces, masses and energies - those are not communicated across the embedding MD code and colvars. so it is mostly important to document carefully how those are defined, in case there could be ambiguities and - perhaps - offer a unit specifier in the input, but that is probably more trouble than worth it. cp2k does that and it is a bit of a mess and confusing to many people. probably the best strategy to proceed is to first make a list of what codes you want to interface to, and decide how much effort you want to invest. for a code like LAMMPS, for example, we can also make the interface refuse to work, if an incompatible unit set it used. |
I think the angles can safely stay in degrees. Using radians is impractical for inputting "exact" angles such as 90°, 120°, etc. Multiples of pi are more convenient, but have the same disadvantages as degrees to evaluate functions. Regarding the unit of length and energy: we aren't following the NAMD convention in a hard-coded way. Unless anyone has changed the code everywhere and not committed yet, those two units are the same the MD program uses: if LAMMPS switches units, so will the colvars module. (Unless, Axel, the unit conversion is only done during I/O?) The unit_angstrom() proxy function is only used to convert hard-coded default values into the units of the hosting program (e.g. nm, au, etc). |
Right now the documentation mentions Angstroms and kcal/mol all the time. This would have to be adapted somehow. |
That is true. But it is only a drawback of the documentation. The only default energy constants are metadynamics' hillWeight, where I put a strong warning against blindingly using the default, and harmonic's forceConstant, for which at this point we can even remove the default value of 1 "kcal/mol" and let it be defined explicitly. For the doc: how about adding a small subsection of "General parameters and input/output files", where we define what the units of length and energy are with a macro, and then replace \AA and kcal/mol in the following with that? I don't have extensive experience with all the units in LAMMPS, and I like scaled units more than the average chemist does: so you two please figure out how to name these macros and how to document them. I'm also open to rediscuss the scaled force constant of "harmonic", for as long as the discussion converges quickly. Whatever is decided, I'll use it to change how the hillWeight option in metadynamics is treated. |
Solved by 80b8acf |
The various extended-Lagrangian options are not compatible with multiple unit systems, and while they are intuitive in the fs-based ones (NAMD, LAMMPS with units real), their values are not easy to convert to other systems to override default values. |
Situation clarified a little by 376e173. The only limitation at this point is extendedLangevinDamping required in ps-1, which I think is not too much of a constraint. We take advantage of the proxy converting internal time units to fs. |
What about extendedTimeConstant, which assumes fs?
Also, the ps-fs issue is a small thing but it is still rather NAMD-specific. In the LAMMPS version of the Langevin thermostat: |
I could have the proxy expose a conversion factor for time units, and then take user input in whatever LAMMPS is setup to use. That would break current inputs that provide fs and ps-1, though. We need a good medium to warn our LAMMPS users of this change. |
For breaking with a previous convention the cleanest way would be to have a new keyword replace the old one (as we did with As one possibility, the proxy already provides the integration time step through I propose the following new keywords:
Once all time constants are at least in the same unit, I can add support for other |
Sounds good. I'm sure I've simulated I think the "fs (NAMD) or LAMMPS time unit" option is ideal. But then I would introduce the new keywords at the same time as support for the LAMMPS units, so that the new keywords have their final meaning from the onset. That's something I can do btw, it's not the more arcane parts of the LAMMPS proxy. |
If you use steps, then there is nothing to do for LAMMPS. If you keep using fs, the LAMMPS proxy will need to get the unit style from the LAMMPS object. The |
I see the proxy already accesses |
Theoretically yes (see But depending on what operations we do with the timestep I'm not sure if it's always safe to count on it for e.g. This is why I'd like to disable the default values for the new keywords in LAMMPS, if you do keep fs units for them. |
The only usage we make of timestep is within the extended Lagrangian integrator, the plan is to keep it that way. And the unit would be 'time unit' in general, and fs only in NAMD. I'm ok to have no default value - I can always recommend one in the doc, specifying its unit. |
If you are removing the default values the issue is most definitely closed with the commit that does it. |
Hi, can you push any commits done for this on a branch? I think that with the refactored |
This issue has gained a new degree of urgency with the Gromacs proxy. The current strategy that mostly uses the back-end's units both internally and for IO purposes makes it complicated to run the tests and compare their results. At this point my favored approach would be to create options to specify units for I/O, but keep the back-end units internally to avoid the overhead of unit conversion when talking to the back-end. |
Well, the introduction of different units for I/O will also need to be tested carefully, requiring comparable work to the testing of a new interface. Can you try running the tests in the native units of the host code, and then load the trajectories using the As a general rule, I'd like to avoid major code changes without first exploring alternatives to |
(Continuing from PR #190) I think it's best to keep using the same units as the MD engine: it would be a nightmare to switch, and also to deal with script callbacks. More in general, Colvars has so far been well integrated in each engine (with varying depth) and for the most part interchangeable with its other features. Specifying a separate unit system for runtime objects would lead to an independent code, which is linked to the main engine following something akin a multi-physics simulation: this use case is already well covered by PLUMED. The issue of moving input files from one code to another is real, but is mostly arising now thanks to the Dashboard, which enables researchers to write complex inputs without quantitative and technical skills sufficient to convert their input's units with small effort. It should be possible, then, to reuse config files that work in VMD in other codes with different units. There are possibly two alternatives to support it:
|
This sounds like a very good idea to me, because that way the files remain portable. I prefer it to the other option, where you'd have to dedicate a file specifically to Gromacs when saving it, and then if you read it again in VMD you'll get another unit conflict. So yeah, I vote for option #1 hands down. It's also extensible, reasonably future-proof. As to the name "vmd", I'm not as sure because vmd doesn't really care about energy units. How about two arguments, length and energy? |
Decision reached from in-person conversation: detect incompatible unit systems with units keyword, throw error. Rationale: we have no mechanism to do unit conversion internally, because we have no way to track the dimensionality of our numerical parameters (especially with user-defined functions). |
This question is arising again now that we have a user base trying to make VMD and Gromacs interoperate. |
Interestingly, this issue is approximately as old as this one: Having said that, let's assume that a new
The logic could be the following:
When a solution is agreeable, tt's probably best to take the opportunity to also update the values of fundamental constants, such as |
This is roughly what I'm tending towards. With the exception of VMD, which I think can actually handle different unit systems. That's key to letting Gromacs users benefit from the VMD interface, that is the reason I'm getting into this again. |
In the How about beginning from just using the |
While working on the fairly simple-minded technical solution in #295 I've come across a possible issue in the current master branch. The XYZ reader of colvarmodule does not do any coordinate conversion, implicitly assuming that the coordinates are in the Colvars length unit. However the closest thing there is to a convention, as far as I can see, is that XYZ files have coordinates in Angstrom. VMD, used by different communities, will read them and assume Angstroms. The Gromacs integration branch already has a change where cvm::load_coords_xyz does the conversion from Angstrom to the current unit. Once merged this would also affect LAMMPS. I suspect that a majority of LAMMPS/Colvars users work in Angstroms, but I'm not sure. My favored course of action would be to change the XYZ parser to always convert from Angstrom, but maybe communicate that to LAMMPS users through some channel. @giacomofiorin @akohlmey Thoughts? |
With an updated VMD and not-updated MD engines, the worst case scenario is that the |
In LAMMPS one can query the current unit setting and there are some conversion factors already available. Thus the LAMMPS colvars proxy already contains code that assembles a conversion factor from native LAMMPS units to angstrom, the time step converted into femtoseconds and the value of the Boltzmann constant in native units. |
@akohlmey It does, but currently the XYZ parser does not use that code, implicitly assuming that coordinates in the XYZ files do not need to be converted. I'm proposing to change that. |
In principle, forcing the XYZ reader to only use Angstrom units seems reasonable. But before making a final decision it's best to consider also the inline coordinate reader (e.g. Note: while I am strongly in favor of having well-defined units for each file format, the XYZ format is used in several more codes than VMD; VMD probably just has the most users. In some cases, atomic units are used (although I agree that's not good practice). So in summary I'd be OK with putting the coordinate conversion of the XYZ reader into |
My reasoning about the inline reader is that coordinates specified within a config string should be in the same unit system as everything else within that same config string. Whereas XYZ files can be used independently, and usually come from a different workflow. |
I pushed a commit to #295 that also contains a warning. To avoid flooding the output, the warning is printed only upon first use of cvm::load_coords_xyz(). What do you think? |
At this point, we follow the NAMD conventions of Angstroms, kcal/mol, angles in degrees. Is that acceptable for other codes? How flexible can and should we make that?
The text was updated successfully, but these errors were encountered: