Skip to content

Commit 8a16ad2

Browse files
committed
I do not remember
1 parent 09cc8d8 commit 8a16ad2

2 files changed

Lines changed: 61 additions & 26 deletions

File tree

Modules/Cluster.py

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,14 @@ def prepare_input_file(self, structure, calc, label):
532532
"""
533533

534534
# Prepare the input file
535-
atm = structure.get_ase_atoms()
536-
atm.set_calculator(calc)
537-
ase.io.write("%s/%s.pwi"% (self.local_workdir, label),
538-
atm, **calc.parameters)
535+
calc.set_directory(self.local_workdir)
536+
calc.set_label(label)
537+
calc.write_input(structure)
538+
539+
print("LBL: {} | PREFIX: {}".format(label, calc.input_data["control"]["prefix"]))
540+
541+
#ase.io.write("%s/%s.pwi"% (self.local_workdir, label),
542+
# atm, **calc.parameters)
539543

540544

541545

@@ -603,6 +607,25 @@ def submit(self, script_location):
603607

604608
return self.ExecuteCMD(cmd, True, return_output=True)
605609

610+
def get_output_path(self, label):
611+
"""
612+
Given the label of the submission, retrive the path of all the output files of that calculation
613+
"""
614+
615+
out_filename = os.path.join(self.workdir, label + ".pwo")
616+
return [out_filename]
617+
618+
def read_results(self, calc, label):
619+
"""
620+
Return a dictionary of the computed property for the given calculation label
621+
"""
622+
623+
#calc.set_label("%s/%s" % (self.local_workdir, label))
624+
calc.set_directory(self.local_workdir)
625+
calc.set_label(label)
626+
calc.read_results()
627+
return copy.deepcopy(calc.results)
628+
606629
def batch_submission(self, list_of_structures, calc, indices,
607630
in_extension, out_extension,
608631
label = "ESP", n_togheder=1):
@@ -722,24 +745,24 @@ def batch_submission(self, list_of_structures, calc, indices,
722745
for i in submitted:
723746
# Prepare a typical label
724747
lbl = label + "_" + str(indices[i])
725-
out_filename = "%s/%s%s"% (self.workdir, lbl, out_extension)
748+
out_fnames = self.get_output_path(lbl)
749+
#out_filename = "%s/%s%s"% (self.workdir, lbl, out_extension)
726750

727-
# Get the response
728-
cmd = self.scpcmd + " %s:%s %s/" % (self.hostname, out_filename,
729-
self.local_workdir)
730-
cp_res = self.ExecuteCMD(cmd, False)
731-
#cp_res = os.system(cmd + " > /dev/null")
732-
if not cp_res:
733-
#print "Error while executing:", cmd
734-
#print "Return code:", cp_res
735-
#sys.stderr.write(cmd + ": exit with code " + str(cp_res))
736-
continue
751+
for out in out_fnames:
752+
# Get the response
753+
cmd = self.scpcmd + " %s:%s %s/" % (self.hostname, out,
754+
self.local_workdir)
755+
cp_res = self.ExecuteCMD(cmd, False)
756+
#cp_res = os.system(cmd + " > /dev/null")
757+
if not cp_res:
758+
#print "Error while executing:", cmd
759+
#print "Return code:", cp_res
760+
#sys.stderr.write(cmd + ": exit with code " + str(cp_res))
761+
continue
737762

738763
# Get the results
739764
try:
740-
calc.set_label("%s/%s" % (self.local_workdir, lbl))
741-
calc.read_results()
742-
results[i] = copy.deepcopy(calc.results)
765+
results[i] = self.read_results(calc, lbl)
743766
except:
744767
pass
745768

@@ -1208,6 +1231,7 @@ def compute_ensemble_batch(self, ensemble, ase_calc, get_stress = True, timeout=
12081231

12091232
# Setup if the ensemble has the stress
12101233
ensemble.has_stress = get_stress
1234+
ensemble.all_properties = [None] * ensemble.N
12111235

12121236
# Check if the working directory exists
12131237
if not os.path.isdir(self.local_workdir):
@@ -1225,15 +1249,14 @@ def compute_single_jobarray(jobs_id, calc):
12251249

12261250
for i, res in enumerate(results):
12271251
num = jobs_id[i]
1252+
1253+
if res is None:
1254+
continue
12281255

12291256
# Check if the run was good
1230-
try:
1231-
resk = res.keys()
1232-
except:
1233-
continue
1234-
check_e = "energy" in resk
1235-
check_f = "forces" in resk
1236-
check_s = "stress" in resk
1257+
check_e = "energy" in res
1258+
check_f = "forces" in res
1259+
check_s = "stress" in res
12371260

12381261
is_success = check_e and check_f
12391262
if get_stress:
@@ -1242,6 +1265,7 @@ def compute_single_jobarray(jobs_id, calc):
12421265
if not is_success:
12431266
continue
12441267

1268+
ensemble.all_properties[num] = copy.deepcopy(res)
12451269
ensemble.energies[num] = res["energy"] / units["Ry"]
12461270
ensemble.forces[num, :, :] = res["forces"] / units["Ry"]
12471271
if get_stress:

Modules/Ensemble.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import sscha.Parallel as Parallel
3535
from sscha.Parallel import pprint as print
3636

37+
import json
38+
3739
import difflib
3840

3941
import SCHAModules
@@ -95,7 +97,11 @@
9597
UNITS_DEFAULT = "default"
9698
UNITS_HARTREE = "hartree"
9799
SUPPORTED_UNITS = [UNITS_DEFAULT, UNITS_HARTREE]
98-
100+
class NumpyEncoder(json.JSONEncoder):
101+
def default(self, obj):
102+
if isinstance(obj, np.ndarray):
103+
return obj.tolist()
104+
return json.JSONEncoder.default(self, obj)
99105

100106
class Ensemble:
101107
__debug_index__ = 0
@@ -127,6 +133,7 @@ def __init__(self, dyn0, T0, supercell = None, **kwargs):
127133
self.forces = []
128134
self.stresses = []
129135
self.xats = []
136+
self.all_properties = []
130137
self.units = UNITS_DEFAULT
131138

132139
self.sscha_energies = []
@@ -762,6 +769,10 @@ def save_bin(self, data_dir, population_id = 1):
762769
np.save("%s/stresses_pop%d.npy" % (data_dir, population_id), self.stresses)
763770

764771
self.dyn_0.save_qe("%s/dyn_gen_pop%d_" % (data_dir, population_id))
772+
773+
if len(self.all_properties):
774+
with open(os.path.join(data_dir, "all_properties_pop%d.json" % population_id), "w") as fp:
775+
json.dump({"properties" : self.all_properties}, fp)
765776

766777
def save_enhanced_xyz(self, filename, append_mode = True, stress_key = "virial", forces_key = "force", energy_key = "energy"):
767778
"""

0 commit comments

Comments
 (0)