Molly.jl
                                
                                
                                
                                    Molly.jl copied to clipboard
                            
                            
                            
                        Improving tests
I noticed that the current tests only check if the simulation doesn't error, but not if the results are wrong. Since I'm refactoring several internal components, I think I should be careful not to change the results. To this end I was thinking to check for some general properties of the simulation to ensure that it is correct. I was thinking of checking for the energy of the system. Do you have any other ideas?
Yes, this is something we need. Since it's not thoroughly tested I'm not fully confident in the implementation as is. Some ideas in addition to the energy would be:
- Temperature, when using a thermostat.
 - Sanity checks of no atoms too close and no atoms outside the bounding box.
 - Test the radial distribution function is sufficiently close to what is expected.
 - RMSD, for molecular examples.
 
About the energy, I was thinking of implementing this as an EnergyLogger. So users would add EnergyLogger(10) to the loggers to record the energy every 10 steps. The energy function would be defined for the in-built forces. Users could define their own alongside their custom force function, but if they don't it would default to returning 0.0. log_property! for the EnergyLogger would loop over all the interactions, sum up the energies and store them. Let me know if you have any input on that idea.
Regarding the energy we could look at the
- value of the energy or of the energy / particle
 - energy error (
E(t)-E_initial) 
For both we could look at the time evolution or at the final value only. If we look at the energy value, we would need some results to compare with and I'm not sure where to look for those. For the energy error I can use the results from NBodySimulator as guidance, but I'd appreciate if you could give me some references.
The problem that I am also facing with the solver benchmarks in https://github.com/SciML/DiffEqBenchmarks.jl/pull/106 is that the energy (in the case of a Lennard Jones potential) has a quite large variation.
There are also some tests in the NBodySimulator.jl repo which I could try to port to Molly.
Indeed, testing stochastic systems is difficult. I don't know any references off the top of my head but will keep an eye out.
Fixing the starting coordinates and velocities should lead to fixed output to within numerical error when not using a stochastic thermostat, we can use that to some degree.
Porting tests for NBodySimulator or elsewhere sounds like a good idea.
Energy, forces and simulation are now compared against OpenMM. Of course there is always more work to do on the tests.