Skip to content

Commit

Permalink
Properly convert list of masses to AiiDA and ASE
Browse files Browse the repository at this point in the history
  • Loading branch information
CasperWA committed Dec 21, 2020
1 parent b13de87 commit 7f2a19f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 4 additions & 2 deletions optimade/adapters/structures/aiida.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def get_aiida_structure_data(optimade_structure: OptimadeStructure) -> Structure
symbols = []
concentration = []
masses = []
mass = 1.0
for index, chemical_symbol in enumerate(kind.chemical_symbols):
# NOTE: The non-chemical element identifier "X" is identical to how AiiDA handles this,
# so it will be treated the same as any other true chemical identifier.
Expand All @@ -63,10 +64,11 @@ def get_aiida_structure_data(optimade_structure: OptimadeStructure) -> Structure

# AiiDA needs a definition for the mass, and for it to be > 0
# mass is OPTIONAL for OPTIMADE structures
masses.append(kind.mass[index] if kind.mass else 1)
masses.append(kind.mass[index] if kind.mass else mass)
mass = sum(masses) if masses else mass

structure.append_kind(
Kind(symbols=symbols, weights=concentration, mass=masses, name=kind.name)
Kind(symbols=symbols, weights=concentration, mass=mass, name=kind.name)
)

# Add Sites
Expand Down
4 changes: 1 addition & 3 deletions optimade/adapters/structures/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ def get_ase_atoms(optimade_structure: OptimadeStructure) -> Atoms:
current_species = species[species_name]

# Argument above about chemical symbols also holds here
mass = None
if current_species.mass:
mass = current_species.mass[0]
mass = sum(current_species.mass) if current_species.mass else None

atoms.append(Atom(symbol=species_name, position=site, mass=mass))

Expand Down

0 comments on commit 7f2a19f

Please sign in to comment.