JuliaMolSim / Molly.jl

Molecular simulation in Julia
Other
371 stars 51 forks source link

Crystal Structure Generation #110

Closed ejmeitz closed 1 year ago

ejmeitz commented 1 year ago

Hello,

I've been working on some code to generate crystal structures and get back a list or coordinates, atoms and the boundary needed to run the simulation. The code is more or less untested and I just wanted to discuss the implementation of the interface. There are many types in this file, but the only ones I intend to export are the functions at the bottom of the file which are not fully implemented. When complete these functions should cover all possible Bravais lattices in 3D and provide sufficient coverage of crystal structure for as a starting place. As it stands, the functions at the bottom of the file (e.g. FCC, Diamond) are just functions that return a crystal type for you. Then you'd have to call replicate_unit_cell to get back the atoms, coords and boundary. I'd prefer this just be one call to FCC() that gives you atoms, coords and boundary,

Some background:

A crystal is defined by a lattice (repeating grid of points) and a basis (atomic pattern at each lattice point). As such the crystal type takes a BravaisLattice, and Vector of BasisAtoms in its constructor. The way in which the Bravais lattice is initialized specifies whether it will be FCC or BCC etc. and the basis atoms allow for more complicated structure like Diamond or Wurtzite to be constructed.

jgreener64 commented 1 year ago

Looks like a good start, this would be useful functionality. I wonder if it could be its own package though? This would let people use it in generic contexts other than Molly, and Molly could depend on it for setup functions or examples.

One issue would be whether you require Molly types, in which case you would have to depend on Molly. It might be easier to use types from AtomsBase.jl as required or define types that are compatible with AtomsBase.jl, for example they have support for boundaries. Short conversion code could then be written in Molly to convert to Molly types.

ejmeitz commented 1 year ago

Yeah that is a good idea. Not sure what to call it Crystals.jl and Bravais.jl are taken. This code is very similar to Bravais.jl although in my opinion has a simpler interface and does not get into the weeds with reciprocal space etc.

I guess leave this pull request open and eventually I'll replace this code with something that calls that library.

jgreener64 commented 1 year ago

Sounds good. Regarding naming there is also the Atomic or Atom prefix, e.g. AtomicCrystals.jl.

ejmeitz commented 1 year ago

Code is mostly done, just making the ReadMe pretty and making sure everything is actually correct: https://github.com/ejmeitz/SimpleCrystals.jl

Thinking about how to interface with Molly now. Main problems will be parsing atom info to build the system and making sure the Cubic/Triclinic simulation boxes get set to the right size. The last part might be kind of annoying since not all of the crystals strictly fill in the 1st octant, some grow in all directions.

Would have to implement 2D triclinic system for full compatibility but that might not be worthwhile.

ejmeitz commented 1 year ago

Are you ok with me adding a second constructor for the System() struct that takes a Crystal struct from the library I made? It would just end up calling the original constructor after it parses the Crystal struct for useful infos.

jgreener64 commented 1 year ago

Yes should be fine.

ejmeitz commented 1 year ago

Cool, almost working now...

One last thing before I fully test it out, what is the difference between fields 1,2, & 5 in AtomData? and what are the res_number and res_name? I have data about the element like its name, symbol etc just confused about what should go where. Thanks!

atom_type::String
atom_name::String
res_number::Int
res_name::String
element::String
jgreener64 commented 1 year ago

These bits of data are quite specific to biomolecular force fields. In that context you have residues forming chains to make proteins. You can just leave them with the default values apart from the element.

atom_type - the force field contains parameters (e.g. σ/ϵ) for each atom type. atom_name - the name of the atom in the residue template, e.g. CD is the delta carbon. res_number - the residue number in the chain. res_name - the name of the residue the atom belongs to, e.g. ALA. element - the element of the atom as a string, e.g. C.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 45.83% and project coverage change: -11.02 :warning:

Comparison is base (fee9cac) 83.63% compared to head (35fba04) 72.61%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #110 +/- ## =========================================== - Coverage 83.63% 72.61% -11.02% =========================================== Files 33 34 +1 Lines 3936 4558 +622 =========================================== + Hits 3292 3310 +18 - Misses 644 1248 +604 ``` | [Impacted Files](https://app.codecov.io/gh/JuliaMolSim/Molly.jl/pull/110?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaMolSim) | Coverage Δ | | |---|---|---| | [src/Molly.jl](https://app.codecov.io/gh/JuliaMolSim/Molly.jl/pull/110?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaMolSim#diff-c3JjL01vbGx5Lmps) | `100.00% <ø> (ø)` | | | [src/analysis.jl](https://app.codecov.io/gh/JuliaMolSim/Molly.jl/pull/110?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaMolSim#diff-c3JjL2FuYWx5c2lzLmps) | `94.44% <ø> (+7.40%)` | :arrow_up: | | [src/cuda.jl](https://app.codecov.io/gh/JuliaMolSim/Molly.jl/pull/110?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaMolSim#diff-c3JjL2N1ZGEuamw=) | `0.00% <0.00%> (ø)` | | | [src/interactions/cosine\_angle.jl](https://app.codecov.io/gh/JuliaMolSim/Molly.jl/pull/110?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaMolSim#diff-c3JjL2ludGVyYWN0aW9ucy9jb3NpbmVfYW5nbGUuamw=) | `100.00% <ø> (ø)` | | | [src/makie.jl](https://app.codecov.io/gh/JuliaMolSim/Molly.jl/pull/110?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaMolSim#diff-c3JjL21ha2llLmps) | `0.00% <0.00%> (ø)` | | | [src/interactions/implicit\_solvent.jl](https://app.codecov.io/gh/JuliaMolSim/Molly.jl/pull/110?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaMolSim#diff-c3JjL2ludGVyYWN0aW9ucy9pbXBsaWNpdF9zb2x2ZW50Lmps) | `60.69% <19.90%> (-29.31%)` | :arrow_down: | | [src/chain\_rules.jl](https://app.codecov.io/gh/JuliaMolSim/Molly.jl/pull/110?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaMolSim#diff-c3JjL2NoYWluX3J1bGVzLmps) | `24.54% <21.18%> (-22.27%)` | :arrow_down: | | [src/neighbors.jl](https://app.codecov.io/gh/JuliaMolSim/Molly.jl/pull/110?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaMolSim#diff-c3JjL25laWdoYm9ycy5qbA==) | `66.41% <48.43%> (-23.53%)` | :arrow_down: | | [src/types.jl](https://app.codecov.io/gh/JuliaMolSim/Molly.jl/pull/110?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaMolSim#diff-c3JjL3R5cGVzLmps) | `70.38% <50.43%> (-3.02%)` | :arrow_down: | | [src/spatial.jl](https://app.codecov.io/gh/JuliaMolSim/Molly.jl/pull/110?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaMolSim#diff-c3JjL3NwYXRpYWwuamw=) | `77.06% <62.79%> (+1.70%)` | :arrow_up: | | ... and [20 more](https://app.codecov.io/gh/JuliaMolSim/Molly.jl/pull/110?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaMolSim) | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

ejmeitz commented 1 year ago

Might delete this branch and restart, idk what happened when I pulled all the CUDA branch. Seems broken though lol.