2626from pydantic import BaseModel , Field , ValidationError , model_validator , conlist , PrivateAttr
2727from pydantic .functional_validators import AfterValidator , BeforeValidator
2828from annotated_types import Len
29+ import mendeleev
2930
3031import yaml
3132import numpy as np
@@ -127,6 +128,7 @@ class Calculation(BaseModel, title='Main input class'):
127128 Field (default = [])]
128129 _element_dict : dict = PrivateAttr (default = {})
129130 kernel : Annotated [int , Field (default = 0 )]
131+ inputfile : Annotated [str , Field (default = '' )]
130132
131133 mode : Annotated [str , Field (default = None )]
132134 lattice : Annotated [str , Field (default = "" )]
@@ -235,14 +237,38 @@ def _validate_all(self) -> 'Input':
235237 raise ValueError ('Unknown format for pressure' )
236238
237239 self ._temperature_input = copy .copy (self .temperature )
238- if self .temperature is None :
239- self ._temperature = None
240+ #guess a melting temp of the system, this will be mostly ignored
241+ #chem = mendeleev.element(self.element[0])
242+ #self._melting_temperature = chem.melting_point
243+ try :
244+ chem = mendeleev .element (self .element [0 ])
245+ self ._melting_temperature = chem .melting_point
246+ except :
247+ self ._melting_temperature = None
248+
249+ if self .temperature == 0 :
250+ #the only situation in which it can be None is if mode is melting temp
251+ if len (self .element ) > 1 :
252+ raise ValueError ("Cannot guess start temperature for more than one species, please specify" )
253+ #now try to guess
254+ if self ._melting_temperature is None :
255+ raise ValueError ("Could not guess start temperature for more than one species, please specify" )
256+ self ._temperature = self ._melting_temperature
257+ self ._temperature_stop = self ._melting_temperature
258+ if self .temperature_high == 0 :
259+ self ._temperature_high = 2 * self ._melting_temperature
260+ else :
261+ self ._temperature_high = self .temperature_high
262+
240263 elif np .shape (np .atleast_1d (self .temperature )) == (1 ,):
241264 temp = np .atleast_1d (self .temperature )
242265 self ._temperature = temp [0 ]
243266 self ._temperature_stop = temp [0 ]
244- if self ._temperature_high is None :
267+ if self .temperature_high == 0 :
245268 self ._temperature_high = 2 * temp [0 ]
269+ else :
270+ self ._temperature_high = self .temperature_high
271+
246272 elif np .shape (self .temperature ) == (2 ,):
247273 temp = self .temperature
248274 self ._temperature = temp [0 ]
@@ -293,16 +319,16 @@ def _validate_all(self) -> 'Input':
293319 if self .lattice == "" :
294320 #fetch from dict
295321 if len (self .element ) > 1 :
296- raise ValueError ("MeltingTemperature can be used only with one element" )
322+ raise ValueError ("Cannot create lattice for more than one element" )
297323 if self .element [0 ] in element_dict .keys ():
298- self .lattice = element_dict [self .element [0 ]]['structure' ]
324+ self .lattice = element_dict [self .element [0 ]]['structure' ]
299325 self .lattice_constant = element_dict [self .element [0 ]]['lattice_constant' ]
300326 else :
301327 raise ValueError ("Could not find structure, please provide lattice and lattice_constant explicitely" )
302328
303329 if self .repeat == [1 ,1 ,1 ]:
304330 self .repeat = [5 ,5 ,5 ]
305-
331+
306332 structure = _make_crystal (self .lattice .lower (),
307333 lattice_constant = self .lattice_constant ,
308334 repetitions = self .repeat ,
@@ -317,7 +343,7 @@ def _validate_all(self) -> 'Input':
317343 self ._element_dict [t ]['composition' ] = typecounts [c ]/ np .sum (typecounts )
318344
319345 self ._natoms = structure .natoms
320- self ._original_lattice = self .lattice
346+ self ._original_lattice = self .lattice . lower ()
321347 write_structure_file = True
322348
323349 elif self .lattice .lower () in structure_dict .keys ():
@@ -347,7 +373,7 @@ def _validate_all(self) -> 'Input':
347373 #self._composition = concdict_frac
348374 #self._composition_counts = concdict_counts
349375 self ._natoms = structure .natoms
350- self ._original_lattice = self .lattice
376+ self ._original_lattice = self .lattice . lower ()
351377 write_structure_file = True
352378
353379 else :
@@ -369,7 +395,7 @@ def _validate_all(self) -> 'Input':
369395 self ._element_dict [t ]['count' ] = typecounts [c ]
370396 self ._element_dict [t ]['composition' ] = typecounts [c ]/ np .sum (typecounts )
371397 self ._natoms = structure .natoms
372- self ._original_lattice = self .lattice
398+ self ._original_lattice = os . path . basename ( self .lattice )
373399 self .lattice = os .path .abspath (self .lattice )
374400
375401 #if needed, write the file out
@@ -435,19 +461,14 @@ def create_identifier(self):
435461 """
436462 #lattice processed
437463 prefix = self .mode
438- if prefix == 'melting_temperature' :
439- ts = int (0 )
440- ps = int (0 )
441- l = 'tm'
464+ ts = int (self ._temperature )
465+ if self ._pressure is None :
466+ ps = "None"
442467 else :
443- ts = int (self ._temperature )
444- if self ._pressure is None :
445- ps = "None"
446- else :
447- ps = "%d" % (int (self ._pressure ))
448- l = self ._original_lattice
449- l = l .split ('/' )
450- l = l [- 1 ]
468+ ps = "%d" % (int (self ._pressure ))
469+ l = self ._original_lattice
470+ l = l .split ('/' )
471+ l = l [- 1 ]
451472
452473 if self .folder_prefix is None :
453474 identistring = "-" .join ([prefix , l .lower (), self .reference_phase , str (ts ), str (ps )])
@@ -524,6 +545,7 @@ def _read_inputfile(file):
524545 calculations = []
525546 for count , calc in enumerate (data ['calculations' ]):
526547 calc ['kernel' ] = count
548+ calc ['inputfile' ] = file
527549 calculations .append (Calculation (** calc ))
528550 return calculations
529551
@@ -559,6 +581,7 @@ def _convert_legacy_inputfile(file, return_calcs=False):
559581 #calc['reference_phase'] = str(ci["reference_phase"]) if "reference_phase" in ci.keys() else 'none'
560582 #calc['lattice_constant'] = float(ci["lattice_constant"]) if "lattice_constant" in ci.keys() else 0
561583 calc ['kernel' ] = cc
584+ calc ['inputfile' ] = file
562585 calculations .append (calc )
563586
564587 else :
@@ -608,6 +631,7 @@ def _convert_legacy_inputfile(file, return_calcs=False):
608631 calc ["pressure" ] = _to_float (combo [1 ])
609632 calc ["temperature" ] = _to_float (combo [2 ])
610633 calc ['kernel' ] = cc
634+ calc ['inputfile' ] = file
611635 cc += 1
612636 calculations .append (calc )
613637
0 commit comments