SimonEnsemble/PorousMaterials.jl

Document use of `rc` to add pseudo-atoms in `Molecule`s

Closed this issue · 3 comments

I would like to define a nitrogen molecule with charges derived from the TraPPE force field. In this setup, point charges of -0.482e are placed on the two nitrogen atoms, and to maintain charge neutrality, a point charge of +0.964e is placed at the center of mass of the nitrogen molecule. This dummy site should have zero mass. Here are my atoms.csv and charges.csv files:

atoms.csv

atom,x,y,z
N_in_N2,0,0,0.55
VOID,0,0,0
N_in_N2,0,0,-0.55

charges.csv

q,x,y,z
-0.482,0,0,0.55
0.964,0,0,0
-0.482,0,0,-0.55

However, when I run molecule = Molecule("N2"), I encounter the following error:

ERROR: KeyError: key :VOID not found
Stacktrace:
  [1] getindex(h::Dict{Symbol, Float64}, key::Symbol)
    @ Base ./dict.jl:484
  [2] (::PorousMaterials.var"#12#13")(x::Symbol)
    @ PorousMaterials ./none:0
  [3] iterate
    @ ./generator.jl:47 [inlined]
  [4] collect_to!(dest::Vector{Float64}, itr::Base.Generator{Vector{Symbol}, PorousMaterials.var"#12#13"}, offs::Int64, st::Int64)
    @ Base ./array.jl:840
  [5] collect_to_with_first!(dest::Vector{Float64}, v1::Float64, itr::Base.Generator{Vector{Symbol}, PorousMaterials.var"#12#13"}, st::Int64)
    @ Base ./array.jl:818
  [6] collect(itr::Base.Generator{Vector{Symbol}, PorousMaterials.var"#12#13"})
    @ Base ./array.jl:792
  [7] center_of_mass(molecule::Molecule{Cart})
    @ PorousMaterials ~/.julia/packages/PorousMaterials/R2E9b/src/molecule.jl:25
  [8] Molecule(species::String; check_neutrality::Bool)
    @ PorousMaterials ~/.julia/packages/PorousMaterials/R2E9b/src/molecule.jl:82
  [9] Molecule(species::String)
    @ PorousMaterials ~/.julia/packages/PorousMaterials/R2E9b/src/molecule.jl:56
 [10] top-level scope
    @ REPL[10]:1

I believe this error occurs because the atomic mass of VOID is not defined. I suggest adding the atomic mass of VOID as zero to the append_atomic_masses() function so that a more general molecule definition can be supported.

We don't include anything like :VOID in the mass list, because some people call it that, others call it :X, still others might call it :None, etc. The user should set whichever one of these they intend to use by adding it to the (exported, global) rc dictionary before calling Molecule:

rc[:atomic_masses][:VOID] = 0.

Thanks for your explanation. That is a more general way to add custom atomic masses. Perhaps this should be documented in the molecules chapter of the documentation?

Yes, that is a very good idea.