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 21 commits into
base: cg-particle-support
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
18 changes: 12 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ maintainers = [
{ name = "Joseph F. Rudzinski", email = "[email protected]" }
]
license = { file = "LICENSE" }
# dependencies = [
# "nomad-lab>=1.3.0",
# "matid>=2.0.0.dev2",
# "nomad-simulations@file:///home/bmohr/software/nomad-simulations",
# ]
dependencies = [
"nomad-lab>=1.3.0",
"matid>=2.0.0.dev2",
Expand All @@ -40,12 +45,13 @@ dependencies = [

[project.optional-dependencies]
dev = [
"mypy==1.0.1",
"ruff",
"pytest",
"pytest-timeout",
"pytest-cov",
"structlog",
'mypy==1.0.1',
'pytest>= 5.3.0, <8',
'pytest-timeout>=1.4.2',
'pytest-cov>=2.7.1',
'ruff>=0.6',
'structlog>=1.0',
'typing-extensions>=4.12',
]

[tool.uv]
Expand Down
4 changes: 2 additions & 2 deletions src/nomad_simulations/schema_packages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class NOMADSimulationsEntryPoint(SchemaPackageEntryPoint):
description='Limite of the number of atoms in the unit cell to be treated for the system type classification from MatID to work. This is done to avoid overhead of the package.',
)
equal_cell_positions_tolerance: float = Field(
1e-12,
description='Tolerance (in meters) for the cell positions to be considered equal.',
12,
description='Decimal order or tolerance (in meters) for comparing cell positions.',
)

def load(self):
Expand Down
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
65 changes: 36 additions & 29 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 @@ -217,7 +224,10 @@ def _set_system_branch_depth(
system_parent=system_child, branch_depth=branch_depth + 1
)

def resolve_composition_formula(self, system_parent: ModelSystem) -> None:
#! Generalize from checks for atomic systems, error with CG input
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 @@ -226,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 @@ -238,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 @@ -258,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 @@ -268,22 +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)

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)
get_composition_recurs(system=subsystem, labels=labels)

# ! CG: system_parent.cell[0].particles_state instead of atoms_state!
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 @@ -308,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