@@ -279,7 +279,7 @@ def check_if_melted(self, lmp, filename):
279279 """ """
280280 solids = ph .find_solid_fraction (os .path .join (self .simfolder , filename ))
281281 if solids / lmp .natoms < self .calc .tolerance .solid_fraction :
282- lmp . close ( )
282+ self . lammps_close ( lmp = lmp )
283283 # Preserve log file on error
284284 logfile = os .path .join (self .simfolder , "log.lammps" )
285285 try :
@@ -296,7 +296,7 @@ def check_if_solidfied(self, lmp, filename):
296296 """ """
297297 solids = ph .find_solid_fraction (os .path .join (self .simfolder , filename ))
298298 if solids / lmp .natoms > self .calc .tolerance .liquid_fraction :
299- lmp . close ( )
299+ self . lammps_close ( lmp = lmp )
300300 # Preserve log file on error
301301 logfile = os .path .join (self .simfolder , "log.lammps" )
302302 try :
@@ -611,7 +611,7 @@ def run_iterative_pressure_convergence(self, lmp):
611611 laststd = std
612612
613613 if not converged :
614- lmp . close ( )
614+ self . lammps_close ( lmp = lmp )
615615 # Preserve log file on error
616616 logfile = os .path .join (self .simfolder , "log.lammps" )
617617 try :
@@ -736,7 +736,7 @@ def run_iterative_constrained_pressure_convergence(self, lmp):
736736 lmp .command ("unfix 2" )
737737
738738 if not converged :
739- lmp . close ( )
739+ self . lammps_close ( lmp = lmp )
740740 # Preserve log file on error
741741 logfile = os .path .join (self .simfolder , "log.lammps" )
742742 try :
@@ -1249,7 +1249,7 @@ def reversible_scaling(self, iteration=1):
12491249 lmp .command ("undump d1" )
12501250
12511251 # close the object
1252- lmp . close ( )
1252+ self . lammps_close ( lmp = lmp )
12531253 # Preserve log file
12541254 logfile = os .path .join (self .simfolder , "log.lammps" )
12551255 if os .path .exists (logfile ):
@@ -1449,8 +1449,8 @@ def temperature_scaling(self, iteration=1):
14491449 )
14501450 lmp .command ("run %d" % self .calc ._n_sweep_steps )
14511451
1452- lmp . close ( )
1453- # Preserve log file
1452+ self . lammps_close ( lmp = lmp )
1453+ # Preserve log file
14541454 logfile = os .path .join (self .simfolder , "log.lammps" )
14551455 if os .path .exists (logfile ):
14561456 os .rename (
@@ -1587,7 +1587,7 @@ def pressure_scaling(self, iteration=1):
15871587 )
15881588 lmp .command ("run %d" % self .calc ._n_sweep_steps )
15891589
1590- lmp . close ()
1590+
15911591 # Preserve log file
15921592 logfile = os .path .join (self .simfolder , "log.lammps" )
15931593 if os .path .exists (logfile ):
@@ -1643,3 +1643,9 @@ def clean_up(self):
16431643
16441644 with open (os .path .join (self .simfolder , "metadata.yaml" ), "w" ) as fout :
16451645 yaml .safe_dump (metadata , fout )
1646+
1647+ def lammps_close (self , lmp ):
1648+ if self ._lmp is None :
1649+ lmp .close ()
1650+ else :
1651+ lmp .clear ()
0 commit comments