|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | from __future__ import print_function |
3 | 3 | import sys, os |
| 4 | +import warnings |
4 | 5 | import numpy as np |
5 | 6 | import time |
6 | 7 |
|
|
33 | 34 |
|
34 | 35 | import sscha.Parallel as Parallel |
35 | 36 | from sscha.Parallel import pprint as print |
| 37 | +from sscha.Tools import NumpyEncoder |
36 | 38 |
|
37 | 39 | import json |
38 | 40 |
|
@@ -133,7 +135,6 @@ def __init__(self, dyn0, T0, supercell = None, **kwargs): |
133 | 135 | self.forces = [] |
134 | 136 | self.stresses = [] |
135 | 137 | self.xats = [] |
136 | | - self.all_properties = [] |
137 | 138 | self.units = UNITS_DEFAULT |
138 | 139 |
|
139 | 140 | self.sscha_energies = [] |
@@ -186,7 +187,7 @@ def __init__(self, dyn0, T0, supercell = None, **kwargs): |
186 | 187 | self.stress_computed = None |
187 | 188 |
|
188 | 189 | # Get the extra quantities |
189 | | - self.extra_quantities = {} |
| 190 | + self.all_properties = [] |
190 | 191 |
|
191 | 192 |
|
192 | 193 | # Setup the attribute control |
@@ -770,9 +771,9 @@ def save_bin(self, data_dir, population_id = 1): |
770 | 771 |
|
771 | 772 | self.dyn_0.save_qe("%s/dyn_gen_pop%d_" % (data_dir, population_id)) |
772 | 773 |
|
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) |
| 774 | + if len(self.all_properties): |
| 775 | + with open(os.path.join(data_dir, "all_properties_pop%d.json" % population_id), "w") as fp: |
| 776 | + json.dump({"properties" : self.all_properties}, fp, cls=NumpyEncoder) |
776 | 777 |
|
777 | 778 | def save_enhanced_xyz(self, filename, append_mode = True, stress_key = "virial", forces_key = "force", energy_key = "energy"): |
778 | 779 | """ |
@@ -960,6 +961,16 @@ def load_bin(self, data_dir, population_id = 1, avoid_loading_dyn = False): |
960 | 961 | # Setup that both forces and stresses are not computed |
961 | 962 | self.stress_computed = np.ones(self.N, dtype = bool) |
962 | 963 | self.force_computed = np.ones(self.N, dtype = bool) |
| 964 | + |
| 965 | + all_prop_fname = os.path.join(data_dir, "all_properties_pop%d.json" % population_id) |
| 966 | + if os.path.exists(all_prop_fname): |
| 967 | + with open(os.path.join(data_dir, "all_properties_pop%d.json" % population_id), "w") as fp: |
| 968 | + props= json.load(fp) |
| 969 | + if "properties" in props: |
| 970 | + self.all_properties = props["properties"] |
| 971 | + else: |
| 972 | + warnings.warn("WARNING: found file {} but not able to load the properties keyword.".format(all_prop_fname)) |
| 973 | + |
963 | 974 |
|
964 | 975 |
|
965 | 976 | def init_from_structures(self, structures): |
|
0 commit comments