Comments (5)
Hi! I tried your code and got the same error. As you pointed out, it relates to how Unitful treats units when doing basic arithmetic. In your code, the coordinates are defined based on the boundary units. Setting the boundary in u"\AA" makes the coordinates be defined in u"\AA", and the same applies to u"nm". However, after calculating the interaction in the Lennard-Jones potential, you end up with mixed units if you are not careful! For example, if you try Unitful in the Julia REPL, you will find that:
julia> 1.0u"nm" / 10.0u"Å"
0.1 nm Å⁻¹
julia> 1.0u"nm" / 1.0u"nm"
1.0
So the units only cancel out if they are the same. It made me scratch my head for some hours.
Regarding not defining \sigma, the interaction follows a shortcut when either \epsilon or \sigma is equal to zero (and returns 0 with the right units):
Molly.jl/src/interactions/lennard_jones.jl
Lines 86 to 89 in 38dec32
And \sigma is set equal to zero by default when you don't specify it in the constructor:
Lines 235 to 243 in 38dec32
This triggers the shortcut, so you don't see the error anymore. I hope this helps! :)
from molly.jl.
Simplest thing is probably to check that the units match in setup and then throw an error if they dont.
from molly.jl.
Yes it seems like check_energy_units
and check_force_units
are too strict and should be re-written to allow a unit conversion. I can take a look later this week.
from molly.jl.
It appears to be non-trivial to allow the unit conversion in a performant way, especially on the GPU.
One option is to document (in both the docs and the error message) that units returned from force/energy functions should be the same as the system force/energy units, not just valid for conversion. In practice this means that the box size needs to be specified in the same units as appear in the system force units, since the box size is used to get the vector between atoms.
Another option is to do some unit conversion during setup - I am less keen on this.
from molly.jl.
Just adding this cause its relevant to this issue, but changing mass to g/mol
instead of u
also causes issues.
For the code above it specifically breaks in the velocities of the system. I think this is because the random_velocity function assumes the mass units will be u
with the default params.
from molly.jl.
Related Issues (20)
- Links in Docs are broken HOT 2
- Boltzmann Constant in LAMMPS 'real' units does not work HOT 5
- AtomsBase not properly implemented HOT 4
- GPU error with custom pairwise interactions HOT 5
- apply_coupling! method is not found for custom coupling function HOT 2
- Example for new MC membrane barostat HOT 12
- How to cite? HOT 6
- [feature request] velocity-dependent forces HOT 2
- Should we pass more properties (e.g. velocities, step number) to `force`/`potential_energy`? HOT 4
- Should we have functions to add and remove atoms to/from a `System`? HOT 3
- open an sdf file HOT 10
- Molly.jl: AD with Enyzme returns 0 gradient HOT 1
- Units in Nose Hoover temperature HOT 1
- GPU error with the example HOT 4
- return type for force for pairwise potential in CUDA HOT 1
- sys.coords does not work as Vector{Vector} HOT 2
- EAM implementation and dimension error HOT 5
- Boundary Conditions HOT 1
- UndefVarError: `σ6` not defined ERROR when simulating the NPT ensemble HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from molly.jl.