Skip to content

Commit

Permalink
added isotopes
Browse files Browse the repository at this point in the history
  • Loading branch information
OMalenfantThuot committed Jun 20, 2023
1 parent 2e64683 commit 7702c6b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
20 changes: 15 additions & 5 deletions mlcalcdriver/base/posinp.py
Expand Up @@ -205,7 +205,8 @@ def _from_lines(cls, lines):
for line in lines:
atom_type = line[0]
position = np.array(line[1:4], dtype=float)
atoms.append(Atom(atom_type, position))
isotope = line[4] if len(line) > 4 else None
atoms.append(Atom(atom_type, position, isotope=isotope))
return cls(atoms, units, boundary_conditions, cell=cell, angles=angles)

@classmethod
Expand Down Expand Up @@ -717,7 +718,7 @@ class Atom(object):
Class allowing to represent an atom by its type and position.
"""

def __init__(self, atom_type, position):
def __init__(self, atom_type, position, isotope=None):
r"""
Parameters
----------
Expand All @@ -738,7 +739,8 @@ def __init__(self, atom_type, position):
# TODO: Check that the atom type exists
self.type = atom_type
self.position = position
self.mass = ATOMS_MASS[self.type]
self.isotope = isotope
self.mass = ATOMS_MASS[self.isotope] if self.isotope else ATOMS_MASS[self.type]

@classmethod
def from_dict(cls, atom_dict):
Expand Down Expand Up @@ -831,7 +833,11 @@ def __str__(self):
String representation of the atom, mainly used to create the
string representation of a Posinp instance.
"""
return "{t} {: .15} {: .15} {: .15}\n".format(t=self.type, *self.position)
return (
f"{self.type} {self.position[0]:.15} {self.position[1]:.15} {self.position[2]:.15} {self.isotope}\n"
if self.isotope
else f"{self.type} {self.position[0]:.15} {self.position[1]:.15} {self.position[2]:.15}\n"
)

def __repr__(self):
r"""
Expand All @@ -840,7 +846,11 @@ def __repr__(self):
str
General string representation of an Atom instance.
"""
return "Atom('{}', {})".format(self.type, list(self.position))
return (
"Atom('{}', {}, {})".format(self.type, list(self.position), self.isotope)
if self.isotope
else "Atom('{}', {})".format(self.type, list(self.position))
)

def __eq__(self, other):
r"""
Expand Down
5 changes: 4 additions & 1 deletion mlcalcdriver/globals.py
Expand Up @@ -10,6 +10,9 @@
"Be": 9.012182,
"B": 10.811,
"C": 12.011,
"C12": 12,
"C13": 13.003,
"C14": 14.003,
"N": 14.00674,
"O": 15.9994,
"F": 18.9984032,
Expand Down Expand Up @@ -99,7 +102,7 @@
"Np": 237.048,
"Pu": 244.064,
"Am": 243.061,
"Cm": 247.070
"Cm": 247.070,
}
r"""
`Dictionnary` containing elemental masses, in atomic mass units.
Expand Down

0 comments on commit 7702c6b

Please sign in to comment.