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

Add repeat #157

Merged
merged 12 commits into from
Aug 6, 2024
Merged
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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.9.9
current_version = 0.9.10
commit = True
tag = False

Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ url: 'https://atomrdf.pyscal.org'
license: "MIT"
repository-code: https://github.com/pyscal/atomRDF
type: software
version: 0.9.9
version: 0.9.10
9 changes: 9 additions & 0 deletions atomrdf/network/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ def patch_terms(iri, rn):
elif iri == "http://purls.helmholtz-metadaten.de/cmso/hasValue":
rn = ["float", "double", "int", "str"]

elif iri == "http://purls.helmholtz-metadaten.de/cmso/hasRepetition_x":
rn = ["float", "double", "int"]

elif iri == "http://purls.helmholtz-metadaten.de/cmso/hasRepetition_y":
rn = ["float", "double", "int"]

elif iri == "http://purls.helmholtz-metadaten.de/cmso/hasRepetition_z":
rn = ["float", "double", "int"]

elif iri == "http://purls.helmholtz-metadaten.de/asmo/hasValue":
rn = ["float", "double", "int", "str"]

Expand Down
6 changes: 6 additions & 0 deletions atomrdf/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ def get_crystal_structure_name(system):
return None
return system.atoms._lattice

def get_repetitions(system):
if system._structure_dict is None:
return [None, None, None]
if "repetitions" in system._structure_dict.keys():
return system._structure_dict["repetitions"]
return [None, None, None]

def get_bravais_lattice(system):
"""
Expand Down
59 changes: 56 additions & 3 deletions atomrdf/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
from pyscal3.atoms import AttrSetter, Atoms
import pyscal3.core as pc
from pyscal3.core import structure_dict, element_dict
from pyscal3.formats.ase import convert_snap

import pyscal3.operations.input as inputmethods
import pyscal3.operations.serialize as serialize
from pyscal3.formats.ase import convert_snap
import pyscal3.operations.visualize as visualize
import pyscal3.operations.operations as operations

import atomrdf.json_io as json_io
import atomrdf.properties as prp
Expand Down Expand Up @@ -102,6 +104,8 @@ def _make_crystal(
return_structure_dict=True,
primitive=primitive,
)
if 'repetitions' not in sdict.keys():
sdict['repetitions'] = repetitions

s = System(graph=graph, names=names)
s.box = box
Expand Down Expand Up @@ -169,6 +173,10 @@ def _make_general_lattice(
element=element,
return_structure_dict=True,
)

if 'repetitions' not in sdict.keys():
sdict['repetitions'] = repetitions

s = System(graph=graph, names=names)
s.box = box
s.atoms = atoms
Expand Down Expand Up @@ -365,6 +373,7 @@ def _make_dislocation(
'DislocationCharacter': angle_deg,
}

# here we dont add repetitions, since we cannot guarantee
atom_dict = {"positions": positions, "types": types, "species": species}
atom_obj = Atoms()
atom_obj.from_dict(atom_dict)
Expand Down Expand Up @@ -606,6 +615,10 @@ def _make_grain_boundary_inbuilt(
atoms, box, sdict = gb.populate_grain_boundary(
element, repetitions=repetitions, overlap=overlap
)

if 'repetitions' not in sdict.keys():
sdict['repetitions'] = repetitions

s = System(graph=graph, names=names)
s.box = box
s.atoms = atoms
Expand Down Expand Up @@ -797,6 +810,16 @@ def __init__(
mapdict['selection'] = update_wrapper(partial(self._plot_system, plot_style='selection'), self._plot_system)
self.show._add_attribute(mapdict)

self.modify = AttrSetter()
mapdict = {}
mapdict["repeat"] = self.repeat
mapdict["delete"] = self.delete
mapdict["transform_to_cubic_cell"] = update_wrapper(partial(operations.extract_cubic_representation, self), operations.extract_cubic_representation)
mapdict["remap_to_box"] = update_wrapper(partial(operations.remap_to_box, self), operations.remap_to_box)
mapdict["remap_position_to_box"] = update_wrapper(partial(operations.remap_position_to_box, self), operations.remap_position_to_box)
mapdict["embed_in_cubic_box"] = update_wrapper(partial(operations.embed_in_cubic_box, self), operations.embed_in_cubic_box)
self.modify._add_attribute(mapdict)

self.schema = AttrSetter()
mapdict = {
"material": {
Expand All @@ -818,6 +841,7 @@ def __init__(
"length": partial(prp.get_simulation_cell_length, self),
"vector": partial(prp.get_simulation_cell_vector, self),
"angle": partial(prp.get_simulation_cell_angle, self),
"repetitions": partial(prp.get_repetitions, self),
},
"atom_attribute": {
"position": partial(prp.get_position, self),
Expand Down Expand Up @@ -887,6 +911,31 @@ def duplicate(self, only_essential=False):

return new_system

def repeat(self, repetitions):
"""
Repeat the system in each direction by the specified number of times.

Parameters
----------
repetitions : tuple
The number of times to repeat the system in each direction.

Returns
-------
None

Notes
-----
The system is repeated in each direction by the specified number of times.
"""
new_system = self.duplicate()
new_system = operations.repeat(new_system, repetitions)
if new_system._structure_dict is None:
new_system._structure_dict = {}
new_system._structure_dict["repetitions"] = repetitions
new_system.to_graph()
return new_system

def delete(self, ids=None, indices=None, condition=None, selection=False, copy_structure=False):
"""
Delete atoms from the structure.
Expand Down Expand Up @@ -1019,8 +1068,7 @@ def delete(self, ids=None, indices=None, condition=None, selection=False, copy_s
sys.graph.add((sys.sample, PROV.wasGeneratedBy, activity))

return sys



def add_property_mappings(self, output_property, mapping_quantity=None):
if self.graph is None:
return
Expand Down Expand Up @@ -1679,6 +1727,11 @@ def _add_simulation_cell(self):
),
)
)

repetitions = self.schema.simulation_cell.repetitions()
self.graph.add((simulation_cell, CMSO.hasRepetition_x, Literal(repetitions[0], datatype=XSD.integer)))
self.graph.add((simulation_cell, CMSO.hasRepetition_y, Literal(repetitions[1], datatype=XSD.integer)))
self.graph.add((simulation_cell, CMSO.hasRepetition_z, Literal(repetitions[2], datatype=XSD.integer)))
self.simulation_cell = simulation_cell

def _add_simulation_cell_properties(self):
Expand Down
Loading
Loading