Skip to content

Chemspecies update #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 21, 2024
Merged

Conversation

tjjarvinen
Copy link
Collaborator

@tjjarvinen tjjarvinen commented Nov 3, 2024

This is update to ChemicalSpecies.

  • Change info field to name field and make it represent 4 characters
  • Add function atom_name to access the new name field if given, else return atomic_symbol
  • Added masses for isotopes
  • Added symbol X to valid input. Gives weightless particle with atomic number zero

The idea with atom_name is to represent PDB file format defines atom name columns (13-16). While element_symbol represents element columns (77-78)

  1. element_symbol always gives the symbol of the element
  2. atomic_symbol adds isotope information if given
  3. atom_name defaults to atomic_symbol, but overwrites it with atom_name if species has that information.

This works now

julia> ChemicalSpecies(:C)
C

julia> ChemicalSpecies(:C12)
C12

julia> ChemicalSpecies(:C; atom_name=:MyC)
C

julia> ChemicalSpecies(:C13; atom_name=:MyC)
C13

julia> ChemicalSpecies(:X)
X

Comparisons

The basic idea is that if no isotope or name information is given, then that ChemicalSpecies works as a general atom with that atomic number.

atom_name on the other hand is used to distinguish atoms with same type of atoms.

# true
ChemicalSpecies(:C13) == ChemicalSpecies(:C)

# false
ChemicalSpecies(:C12) == ChemicalSpecies(:C13)

# true
ChemicalSpecies(:C; atom_name=:MyC) == ChemicalSpecies(:C)

# true
ChemicalSpecies(:C12; atom_name=:MyC) == ChemicalSpecies(:C12)

# false
ChemicalSpecies(:C; atom_name=:MyC) == ChemicalSpecies(:C12)

# true
ChemicalSpecies(:C12; atom_name=:MyC) == ChemicalSpecies(:C)

# true
ChemicalSpecies(:C; atom_name=:MyC) == ChemicalSpecies(:C12; atom_name=:MyC)

So basically, you can create a potential using ChemicalSpecies(:C). Users can then mark their systems with isotopes or atomic names, for some additional information and the potential that uses "the general carbon" works with them.

masses

julia> mass(ChemicalSpecies(:C))
12.011 u

julia> mass(ChemicalSpecies(:C12))
12.0 u

julia> mass(ChemicalSpecies(:C13))
13.003354835340001 u

julia> mass(ChemicalSpecies(:C; atom_name=:MyC))
12.011 u

julia> mass(ChemicalSpecies(:C13; atom_name=:MyC))
13.003354835340001 u

julia> mass(ChemicalSpecies(:X))
0.0 u

@mfherbst @cortner

edit. changed atomic_name to atom_name

@rashidrafeek
Copy link
Contributor

just a suggestion: atomic_name seems to imply the name is a property of the atom itself instead of an identifier (which seems to be the case here). Wouldn't just atom_name be better which also matches the PDB defintion?

@tjjarvinen
Copy link
Collaborator Author

This is now up for review and merge.

just a suggestion: atomic_name seems to imply the name is a property of the atom itself instead of an identifier (which seems to be the case here). Wouldn't just atom_name be better which also matches the PDB defintion?

I agree with this one and made the change.

This is of course up for a debate, so feel free to state your opinions.

@cortner
Copy link
Member

cortner commented Nov 12, 2024

I read through and at least for the use-cases I can envision at the moment I am happy. For me this is ok to merge for now.

There is one small item worth thinking about : I find it odd to have a large table of isotope data in a julia source file rather than a JSON or similar. But this is just a matter of preference and I don't feel very strongly about it.

@tjjarvinen
Copy link
Collaborator Author

Fixed a bug where ChemicalSpecies(:U238) and similar did not work correctly.

There is one small item worth thinking about : I find it odd to have a large table of isotope data in a julia source file rather than a JSON or similar. But this is just a matter of preference and I don't feel very strongly about it.

The reasoning here was that having JSON or similar would add more dependencies. So, having it in julia source allows minimizing dependencies.

"""
Encodes a chemical species by wrapping an integer that represents the atomic
number, the number of protons, and additional unspecified information as a `UInt32`.
number, the number of protons, and additional name as max 4 characters.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the drive-by comment, but why are you limiting the name to 4 characters? This is the limit for the obsolete PDB format, but for example the mmcif format that replaced it does not have any length limitation: https://mmcif.wwpdb.org/dictionaries/mmcif_pdbx_v40.dic/Items/_chem_comp_atom.atom_id.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to have a bits type you need to have fixed amount of bits. This leads to a limitation on character length, which for now is 4*8bit char. We could of course increase it later on (there are several ways to do this). But the main design goal was to have it as bits type, which e.g., allows moving atom types to GPU etc.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough!

@rkurchin
Copy link
Collaborator

This looks good to me also – should we link this with #115 so it will close when this is merged?

Copy link
Member

@mfherbst mfherbst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks for the extension.

str_symbol = String(asymbol)
tmp = 0
if length(str_symbol) > 1 && isnumeric(str_symbol[end])
# We only consider cases where number of nucleons is < 1000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@assert somewhere on n_neutrons and/or elsewhere to avoid this gets triggered without notice ?

end
end
asymbol = Symbol(str_symbol)
z = haskey(_sym2z, asymbol) ? _sym2z[asymbol] : 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 3-argument get with default

More broadly: is this a good idea, I mean typos and small missmatches lead to a zero here, which could lead to subtle bugs, no? Same with the other lookups

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the subtle bugs are possible here.

We could also have it error, if symbol is not recognized and is not :X. This would probably be the safest option.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a check for symbols and now symbols that are not recognized throw an ArgumentError.

@@ -221,3 +284,29 @@ of identifying the type of a `species` (e.g. the element for the case of an atom
this may be `:D` while `atomic_number` is still `1`.
"""
atomic_number(sys::AbstractSystem, index) = atomic_number.(species(sys, index))


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a few newlines

@tjjarvinen
Copy link
Collaborator Author

Everything should now be ok with this PR.

Copy link
Member

@mfherbst mfherbst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@mfherbst
Copy link
Member

Unless there are objections I'll merge this tomorrow.

@mfherbst mfherbst enabled auto-merge (squash) November 21, 2024 05:48
@mfherbst mfherbst merged commit f2d862d into JuliaMolSim:master Nov 21, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants