-
Notifications
You must be signed in to change notification settings - Fork 46
/
structure.py
225 lines (158 loc) · 7.27 KB
/
structure.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# 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 pyiron.atomistics.structure.atoms import Atoms
from pyiron.atomistics.master.parallel import ParallelMaster
from pyiron.base.master.parallel import JobGenerator
"""
The StructureListMaster class is a parallel master consisting of a list of structures which are executed in parallel.
"""
__author__ = "Jan Janssen"
__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, 2018"
class StructureJobGenerator(JobGenerator):
"""
JobGenerator for the StructureListMaster - this class implements the functions to generate the parameter list,
modify the individual jobs according to the parameter list and generate the new job names according to the
parameter list.
"""
@property
def parameter_list(self):
"""
Returns:
(list): [[index(int), pyiron.atomistics.structure.atoms.Atoms], ...]
"""
return list(enumerate(self._job.structure_lst))
@staticmethod
def job_name(parameter):
"""
Generate job name for a give set of parameters
Args:
parameter: For the StructureListMaster the structures are simply numbered - struct_0, struct_1, ...
Returns:
str: job name for the next job
"""
return "struct_" + str(parameter[0])
def modify_job(self, job, parameter):
"""
Modify the next job by setting the structure for the specific parameter
Args:
job (GenericJob): next job object to be executed
parameter: includes the atomistic structure
Returns:
GenericJob:
"""
job.structure = parameter[1]
return job
class StructureListMaster(ParallelMaster):
"""
The GenericMaster is the template class for all meta jobs - meaning all jobs which contain multiple other jobs. It
defines the shared functionality of the different kind of job series.
Args:
project (ProjectHDFio): ProjectHDFio instance which points to the HDF5 file the job is stored in
job_name (str): name of the job, which has to be unique within the project
Attributes:
.. attribute:: job_name
name of the job, which has to be unique within the project
.. attribute:: status
execution status of the job, can be one of the following [initialized, appended, created, submitted,
running, aborted, collect, suspended, refresh,
busy, finished]
.. attribute:: job_id
unique id to identify the job in the pyiron database
.. attribute:: parent_id
job id of the predecessor job - the job which was executed before the current one in the current job series
.. attribute:: master_id
job id of the master job - a meta job which groups a series of jobs, which are executed either in parallel
or in serial.
.. attribute:: child_ids
list of child job ids - only meta jobs have child jobs - jobs which list the meta job as their master
.. attribute:: project
Project instance the jobs is located in
.. attribute:: project_hdf5
ProjectHDFio instance which points to the HDF5 file the job is stored in
.. attribute:: job_info_str
short string to describe the job by it is job_name and job ID - mainly used for logging
.. attribute:: working_directory
working directory of the job is executed in - outside the HDF5 file
.. attribute:: path
path to the job as a combination of absolute file system path and path within the HDF5 file.
.. attribute:: version
Version of the hamiltonian, which is also the version of the executable unless a custom executable is used.
.. attribute:: executable
Executable used to run the job - usually the path to an external executable.
.. attribute:: library_activated
For job types which offer a Python library pyiron can use the python library instead of an external
executable.
.. attribute:: server
Server object to handle the execution environment for the job.
.. attribute:: queue_id
the ID returned from the queuing system - it is most likely not the same as the job ID.
.. attribute:: logger
logger object to monitor the external execution and internal pyiron warnings.
.. attribute:: restart_file_list
list of files which are used to restart the calculation from these files.
.. attribute:: job_type
Job type object with all the available job types: ['ExampleJob', 'SerialMaster', 'ParallelMaster',
'ScriptJob', 'ListMaster']
.. attribute:: child_names
Dictionary matching the child ID to the child job name.
"""
def __init__(self, project, job_name):
super(StructureListMaster, self).__init__(project, job_name)
self.__name__ = "StructureListMaster"
self.__version__ = "0.0.1"
self._job_generator = StructureJobGenerator(self)
self._structure_lst = []
@property
def structure_lst(self):
return self._structure_lst
@structure_lst.setter
def structure_lst(self, structure_lst):
self._structure_lst = structure_lst
def to_hdf(self, hdf=None, group_name=None):
"""
Store the StructureListMaster object in the HDF5 File
Args:
hdf (ProjectHDFio): HDF5 group object - optional
group_name (str): HDF5 subgroup name - optional
"""
super(StructureListMaster, self).to_hdf(hdf=hdf, group_name=group_name)
with self.project_hdf5.open("input/structures") as hdf5_input:
for ind, struct in enumerate(self.structure_lst):
struct.to_hdf(hdf=hdf5_input, group_name="s_" + str(ind))
def from_hdf(self, hdf=None, group_name=None):
"""
Restore the StructureListMaster object in the HDF5 File
Args:
hdf (ProjectHDFio): HDF5 group object - optional
group_name (str): HDF5 subgroup name - optional
"""
super(StructureListMaster, self).from_hdf(hdf=hdf, group_name=group_name)
with self.project_hdf5.open("input/structures") as hdf5_input:
self._structure_lst = [
Atoms().from_hdf(hdf5_input, group_name)
for group_name in sorted(hdf5_input.list_groups())
]
def collect_output(self):
"""
Implemented for compatibilty
"""
pass
def run_if_interactive_non_modal(self):
"""
Implemented for compatibilty
"""
raise TypeError
def _run_if_busy(self):
"""
Implemented for compatibilty
"""
pass