JuliaMolSim / AtomsBase.jl

A Julian abstract interface for atomic structures.
https://juliamolsim.github.io/AtomsBase.jl/
MIT License
81 stars 16 forks source link

Another `FastSystem` constructor #63

Open rkurchin opened 1 year ago

rkurchin commented 1 year ago

I found myself wanting to be able to construct a FastSystem without needing to explicitly build the lists of atomic data when they could be inferred, so I added a constructor that will infer atomic numbers and masses if you only supply the symbols. We could also merge this into the original one by providing default values for the latter two arguments. I am completely fine changing this to that instead, i.e. removing the new one I added and instead modifying lines 15-20 to be something like:

# constructor to fetch the types where numbers/masses are explicitly provided
function FastSystem(box, boundary_conditions, positions, atomic_symbols, atomic_numbers=getproperty.(element.(atomic_symbols), :number), atomic_masses=getproperty.(element.(atomic_symbols), :atomic_mass))
    FastSystem{length(box),eltype(eltype(positions)),eltype(atomic_masses)}(
        box, boundary_conditions, positions, atomic_symbols, atomic_numbers, atomic_masses
    )
end

...but that's also a little clunky to read. 🤷‍♀️

mfherbst commented 1 year ago

...but that's also a little clunky to read.

Not if you add line breaks?

Also why are atomic symbols special. What if I want to supply the atomic numbers instead? What I'm getting at is that we have a different but similar mechanism in the Atom and I think for consistency they both should support the same sort of stuff.

Also a test would be good ;).

rkurchin commented 1 year ago

Not if you add line breaks?

Also why are atomic symbols special. What if I want to supply the atomic numbers instead? What I'm getting at is that we have a different but similar mechanism in the Atom and I think for consistency they both should support the same sort of stuff.

All fair points. Do you think basically duplicating the version we have for Atom (i.e. anything that can index into PeriodicTable.elements) would suffice here? While I could see someone wanting to pass either symbols or atomic numbers and have the others inferred, I kind of doubt they'd ever want to pass only atomic masses...

Also a test would be good ;).

Absolutely, wanted to just stick in a quick implementation to start this discussion, would for sure add this before merging. 😉

mfherbst commented 1 year ago

@rkurchin Super sorry. I completely forgot about this PR. I'll take another look later today.

mfherbst commented 1 year ago

Yes I would essentially duplicate the version from Atom, i.e. just pass in a list of Identifiers (type AbstractVector{<:AtomId}) and then just use those to extract symbol, number and mass automatically to fill the kwargs).