Skip to content
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

initial investigation into harmonizing particles and atoms #150

Open
wants to merge 3 commits into
base: cg-particle-support
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/nomad_simulations/schema_packages/atoms_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,16 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
)


class AtomsState(Entity):
class State(Entity):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Didn't end up using this after all, but I left it for now in case we need it. But will remove before merge if not

"""
A base section to define the state information of the system.
"""

def __init__(self, m_def: 'Section' = None, m_context: 'Context' = None, **kwargs):
super().__init__(m_def, m_context, **kwargs)


class AtomsState(State):
"""
A base section to define each atom state information.
"""
Expand Down
61 changes: 33 additions & 28 deletions src/nomad_simulations/schema_packages/general.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from typing import TYPE_CHECKING
#! TODO: Why is TYPE_CHECKING False?
from typing import TYPE_CHECKING, List, Iterable, Union

if TYPE_CHECKING:
from collections.abc import Callable

from nomad.datamodel.datamodel import EntryArchive
from structlog.stdlib import BoundLogger
if not TYPE_CHECKING:
from nomad.datamodel.datamodel import (
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This seems to be a general problem, I need to ask someone

EntryArchive,
)
from nomad.metainfo import (
Context,
Section,
)
from structlog.stdlib import (
BoundLogger,
)

import numpy as np
from nomad.config import config
Expand Down Expand Up @@ -218,7 +225,9 @@ def _set_system_branch_depth(
)

#! Generalize from checks for atomic systems, error with CG input
def resolve_composition_formula(self, system_parent: ModelSystem) -> None:
def resolve_composition_formula(
self, system_parent: ModelSystem, logger: 'BoundLogger'
) -> None:
"""Determine and set the composition formula for `system_parent` and all of its
descendants.

Expand All @@ -227,7 +236,7 @@ def resolve_composition_formula(self, system_parent: ModelSystem) -> None:
"""

def set_composition_formula(
system: ModelSystem, subsystems: list[ModelSystem], atom_labels: list[str]
system: ModelSystem, subsystems: list[ModelSystem], labels: list[str]
) -> None:
"""Determine the composition formula for `system` based on its `subsystems`.
If `system` has no children, the atom_labels are used to determine the formula.
Expand All @@ -239,13 +248,15 @@ def set_composition_formula(
to the atom indices stored in system.
"""
if not subsystems:
atom_indices = (
system.atom_indices if system.atom_indices is not None else []
particle_indices = (
system.particle_indices
if system.particle_indices is not None
else []
)
subsystem_labels = (
[np.array(atom_labels)[atom_indices]]
if atom_labels
else ['Unknown' for atom in range(len(atom_indices))]
[np.array(labels)[particle_indices]]
if labels
else ['Unknown' for atom in range(len(particle_indices))]
)
else:
subsystem_labels = [
Expand All @@ -259,7 +270,7 @@ def set_composition_formula(
children_names=subsystem_labels
)

def get_composition_recurs(system: ModelSystem, atom_labels: list[str]) -> None:
def get_composition_recurs(system: ModelSystem, labels: list[str]) -> None:
"""Traverse the system hierarchy downward and set the branch composition for
all (sub)systems at each level.

Expand All @@ -269,23 +280,17 @@ def get_composition_recurs(system: ModelSystem, atom_labels: list[str]) -> None:
to the atom indices stored in system.
"""
subsystems = system.model_system
set_composition_formula(
system=system, subsystems=subsystems, atom_labels=atom_labels
)
set_composition_formula(system=system, subsystems=subsystems, labels=labels)
if subsystems:
for subsystem in subsystems:
get_composition_recurs(system=subsystem, atom_labels=atom_labels)
get_composition_recurs(system=subsystem, labels=labels)

# ! CG: system_parent.cell[0].particles_state instead of atoms_state!
atoms_state = (
system_parent.cell[0].atoms_state if system_parent.cell is not None else []
)
atom_labels = (
[atom.chemical_symbol for atom in atoms_state]
if atoms_state is not None
else []
)
get_composition_recurs(system=system_parent, atom_labels=atom_labels)
labels = []
if system_parent.cell is not None:
labels = system_parent.cell[0].get('labels', logger=logger)

get_composition_recurs(system=system_parent, labels=labels)

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super(Schema, self).normalize(archive, logger)
Expand All @@ -310,7 +315,7 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:

if is_not_representative(model_system=system_parent, logger=logger):
continue
self.resolve_composition_formula(system_parent=system_parent)
self.resolve_composition_formula(system_parent=system_parent, logger=logger)


m_package.__init_metainfo__()
2 changes: 1 addition & 1 deletion src/nomad_simulations/schema_packages/model_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def resolve_orbital_references(
# If the child is not an "active_atom", the normalization will not run
if active_atom.type != 'active_atom':
continue
indices = active_atom.atom_indices
indices = active_atom.particle_indices
for index in indices:
try:
active_atoms_state = atoms_state[index]
Expand Down
Loading
Loading