3030from atomrdf .datamodels .workflow .software import *
3131from atomrdf .datamodels .workflow .method import *
3232from atomrdf .datamodels .workflow .xcfunctional import *
33+ from atomrdf .utils import get_simulation
3334
3435
3536class Simulation (BaseModel , TemplateMixin ):
@@ -191,7 +192,7 @@ def _validate_workflow_manager(cls, v):
191192 return SoftwareAgent (** v )
192193 return v
193194
194- def _add_md_details (self , graph , simulation ):
195+ def _to_graph_md_details (self , graph , simulation ):
195196 # add ensemble
196197 if self .thermodynamic_ensemble :
197198 ensemble = self .thermodynamic_ensemble .to_graph (graph , simulation )
@@ -202,18 +203,94 @@ def _add_md_details(self, graph, simulation):
202203 potential = self .interatomic_potential .to_graph (graph , simulation )
203204 graph .add ((simulation , ASMO .hasInteratomicPotential , potential ))
204205
205- def _add_dft_details (self , graph , simulation ):
206+ @classmethod
207+ def _from_graph_md_details (cls , graph , sim_id ):
208+ sim = get_simulation (graph , sim_id )
209+ ensemble = graph .value (sim , ASMO .hasStatisticalEnsemble )
210+ if ensemble :
211+ cls .thermodynamic_ensemble = ensemble .toPython ().split ("/" )[- 1 ]
212+
213+ potential = graph .value (sim , ASMO .hasInteratomicPotential )
214+ if potential :
215+ pot_type = potential .toPython ().split ("/" )[- 1 ]
216+ if pot_type == "ModifiedEmbeddedAtomModel" :
217+ cls .interatomic_potential = ModifiedEmbeddedAtomModel .from_graph (
218+ graph , potential
219+ )
220+ elif pot_type == "EmbeddedAtomModel" :
221+ cls .interatomic_potential = EmbeddedAtomModel .from_graph (
222+ graph , potential
223+ )
224+ elif pot_type == "LennardJonesPotential" :
225+ cls .interatomic_potential = LennardJonesPotential .from_graph (
226+ graph , potential
227+ )
228+ elif pot_type == "MachineLearningPotential" :
229+ cls .interatomic_potential = MachineLearningPotential .from_graph (
230+ graph , potential
231+ )
232+ else :
233+ cls .interatomic_potential = InteratomicPotential .from_graph (
234+ graph , potential
235+ )
236+ return cls
237+
238+ def _to_graph_dft_details (self , graph , simulation ):
206239 # add XC functional
207240 if self .xc_functional :
208241 xc_functional = self .xc_functional .to_graph ()
209242 graph .add ((simulation , MDO .hasXCFunctional , xc_functional ))
210243
211- def _add_dof (self , graph , simulation ):
244+ @classmethod
245+ def _from_graph_dft_details (cls , graph , sim_id ):
246+ sim = get_simulation (graph , sim_id )
247+ xc_functional = graph .value (sim , MDO .hasXCFunctional )
248+ if xc_functional :
249+ cls .xc_functional = xc_functional .toPython ().split ("/" )[- 1 ]
250+ return cls
251+
252+ def _to_graph_dof (self , graph , simulation ):
212253 if self .degrees_of_freedom :
213254 for dof in self .degrees_of_freedom :
214255 graph .add ((simulation , ASMO .hasRelaxationDOF , dof .to_graph ()))
215256
216- def _add_software (self , graph , simulation ):
257+ @classmethod
258+ def _from_graph_dof (cls , graph , sim_id ):
259+ sim = get_simulation (graph , sim_id )
260+ dofs = [x [2 ] for x in graph .triples ((sim , ASMO .hasRelaxationDOF , None ))]
261+ doflist = []
262+ for dof in dofs :
263+ doflist .append (dof .toPython ().split ("/" )[- 1 ])
264+
265+ if doflist :
266+ cls .degrees_of_freedom = doflist
267+ return cls
268+
269+ def _to_graph_software (self , graph , simulation ):
270+ workflow_manager = None
271+ if self .workflow_manager :
272+ workflow_manager = self .workflow_manager .to_graph (
273+ graph ,
274+ )
275+ graph .add ((simulation , PROV .wasAssociatedWith , workflow_manager ))
276+
217277 if self .software :
218- software = self .software .to_graph ()
219- graph .add ((simulation , ASMO .hasSoftware , software ))
278+ for software in self .software :
279+ softobj = software .to_graph (
280+ graph ,
281+ )
282+ graph .add ((simulation , PROV .wasAssociatedWith , softobj ))
283+ if workflow_manager :
284+ graph .add ((workflow_manager , PROV .actedOnBehalfOf , softobj ))
285+
286+ @classmethod
287+ def _from_graph_software (cls , graph , sim_id ):
288+ sim = get_simulation (graph , sim_id )
289+ workflow_manager = graph .value (sim , PROV .wasAssociatedWith )
290+ if workflow_manager :
291+ cls .workflow_manager = SoftwareAgent .from_graph (graph , workflow_manager )
292+
293+ software = [x [2 ] for x in graph .triples ((sim , PROV .wasAssociatedWith , None ))]
294+ if software :
295+ cls .software = [SoftwareAgent .from_graph (graph , s ) for s in software ]
296+ return cls
0 commit comments