-
Notifications
You must be signed in to change notification settings - Fork 1
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
JFRudzinski
wants to merge
3
commits into
cg-particle-support
Choose a base branch
from
cg-particle-support-JFR
base: cg-particle-support
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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. | ||
|
||
|
@@ -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. | ||
|
@@ -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 = [ | ||
|
@@ -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. | ||
|
||
|
@@ -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) | ||
|
@@ -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__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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