-
Notifications
You must be signed in to change notification settings - Fork 46
/
structurecontainer.py
63 lines (53 loc) · 2.27 KB
/
structurecontainer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.
from __future__ import print_function
from pyiron.atomistics.structure.atoms import Atoms
from pyiron.atomistics.job.atomistic import AtomisticGenericJob
__author__ = "Yury Lysogorskiy"
__copyright__ = (
"Copyright 2020, Max-Planck-Institut für Eisenforschung GmbH - "
"Computational Materials Design (CM) Department"
)
__version__ = "1.0"
__maintainer__ = "Jan Janssen"
__email__ = "janssen@mpie.de"
__status__ = "development"
__date__ = "Sep 1, 2017"
class StructureContainer(AtomisticGenericJob):
def __init__(self, project, job_name):
super(StructureContainer, self).__init__(project, job_name)
self.__version__ = "0.1"
self.__name__ = "StructureContainer"
self.server.run_mode.interactive = True
@property
def structure(self):
return self._structure
@structure.setter
def structure(self, structure):
if isinstance(structure, AtomisticGenericJob):
if structure.structure:
self._structure = structure.get_structure(iteration_step=-1)
self.parent_id = structure.job_id
else:
raise ValueError("The job does not contain any structure to import.")
elif isinstance(structure, Atoms):
self._structure = structure
else:
raise TypeError(
"You can only append a structure object or an GenericJob object."
)
if self.status.initialized:
self.run()
def append(self, structure_to_append):
self.structure = structure_to_append
def run_if_interactive(self):
self.status.finished = True
def to_hdf(self, hdf=None, group_name=None):
super(StructureContainer, self).to_hdf(hdf=hdf, group_name=group_name)
with self.project_hdf5.open("input") as hdf5_input:
self.structure.to_hdf(hdf5_input)
def from_hdf(self, hdf=None, group_name=None):
super(StructureContainer, self).from_hdf(hdf=hdf, group_name=group_name)
with self.project_hdf5.open("input") as hdf5_input:
self.structure = Atoms().from_hdf(hdf5_input)