Skip to content

Commit dc8e62f

Browse files
authored
Merge pull request #45 from ICAMS/update/comp_integration
Update/comp integration
2 parents 5a8a0ce + 84894a5 commit dc8e62f

File tree

17 files changed

+1410
-41
lines changed

17 files changed

+1410
-41
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.2.1
2+
current_version = 1.2.2
33
commit = True
44
tag = True
55

calphy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from calphy.alchemy import Alchemy
55
from calphy.routines import MeltingTemp
66

7-
__version__ = "1.2.1"
7+
__version__ = "1.2.2"
88

99
def addtest(a,b):
1010
return a+b

calphy/alchemy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def run_integration(self, iteration=1):
155155
#remap the box to get the correct pressure
156156
lmp = ph.remap_box(lmp, self.lx, self.ly, self.lz)
157157

158+
lmp.command("velocity all create %f %d mom yes rot yes dist gaussian"%(self.calc._temperature, np.random.randint(0, 10000)))
158159
# Integrator & thermostat.
159160
if self.calc._npt:
160161
lmp.command("fix f1 all npt temp %f %f %f %s %f %f %f"%(self.calc._temperature, self.calc._temperature,
@@ -321,8 +322,8 @@ def thermodynamic_integration(self):
321322

322323

323324
def mass_integration(self, flambda, ref_mass, target_masses, target_counts):
324-
mcorarr = integrate_mass(flambda, ref_mass, target_masses, target_counts,
325+
mcorarr, mcorsum = integrate_mass(flambda, ref_mass, target_masses, target_counts,
325326
self.calc._temperature, self.natoms)
326-
return mcorarr
327+
return mcorarr, mcorsum
327328

328329

calphy/input.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@
3030
import shutil
3131
import numpy as np
3232

33+
def read_report(folder):
34+
"""
35+
Read the finished calculation report
36+
"""
37+
repfile = os.path.join(folder, "report.yaml")
38+
if not os.path.exists(repfile):
39+
raise FileNotFoundError(f"file {repfile} not found")
40+
41+
with open(repfile, 'r') as fin:
42+
data = yaml.safe_load(fin)
43+
return data
44+
3345
class InputTemplate:
3446
def __init__(self):
3547
pass
@@ -93,7 +105,6 @@ def merge_dicts(self, dicts):
93105
merged_dict[key] = val
94106
return merged_dict
95107

96-
97108
class CompositionScaling(InputTemplate):
98109
def __init__(self):
99110
self._input_chemical_composition = None
@@ -157,6 +168,7 @@ def __init__(self):
157168
self._n_print_steps = 0
158169
self._n_iterations = 1
159170
self._equilibration_control = None
171+
self._folder_prefix = None
160172

161173
#add second level options; for example spring constants
162174
self._spring_constants = None
@@ -549,6 +561,14 @@ def spring_constants(self, val):
549561
val = self.check_and_convert_to_list(val, check_none=True)
550562
self._spring_constants = val
551563

564+
@property
565+
def folder_prefix(self):
566+
return self._folder_prefix
567+
568+
@folder_prefix.setter
569+
def folder_prefix(self, val):
570+
self._folder_prefix = val
571+
552572
def fix_paths(self, potlist):
553573
"""
554574
Fix paths for potential files to complete ones
@@ -594,7 +614,11 @@ def create_identifier(self):
594614
l = self.lattice
595615
l = l.split('/')
596616
l = l[-1]
597-
identistring = "-".join([prefix, l, str(ts), str(ps)])
617+
618+
if self.folder_prefix is None:
619+
identistring = "-".join([prefix, l, str(ts), str(ps)])
620+
else:
621+
identistring = "-".join([self.folder_prefix, prefix, l, str(ts), str(ps)])
598622
return identistring
599623

600624
def create_folders(self, prefix=None):
@@ -688,7 +712,8 @@ def read_inputfile(file):
688712
if mode == "melting_temperature":
689713
calc = Calculation.generate(indata)
690714
calc.add_from_dict(ci, keys=["mode", "pair_style", "pair_coeff", "repeat", "n_equilibration_steps",
691-
"n_switching_steps", "n_print_steps", "n_iterations", "spring_constants", "equilibration_control"])
715+
"n_switching_steps", "n_print_steps", "n_iterations", "spring_constants", "equilibration_control",
716+
"folder_prefix"])
692717
calc.pressure = Calculation.convert_to_list(ci["pressure"], check_none=True) if "pressure" in ci.keys() else 0
693718
calc.temperature = Calculation.convert_to_list(ci["temperature"]) if "temperature" in ci.keys() else None
694719
calc.lattice = Calculation.convert_to_list(ci["lattice"]) if "lattice" in ci.keys() else None
@@ -724,7 +749,7 @@ def read_inputfile(file):
724749
calc = Calculation.generate(indata)
725750
calc.add_from_dict(ci, keys=["mode", "pair_style", "pair_coeff", "repeat", "n_equilibration_steps",
726751
"n_switching_steps", "n_print_steps", "n_iterations", "potential_file", "spring_constants",
727-
"melting_cycle", "equilibration_control"])
752+
"melting_cycle", "equilibration_control", "folder_prefix"])
728753
calc.lattice = combo[0]["lattice"]
729754
calc.lattice_constant = combo[0]["lattice_constant"]
730755
calc.reference_phase = combo[0]["reference_phase"]

calphy/integrators.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,15 @@ def find_w(mainfolder, nelements=1, concentration=[1,], nsims=5, full=False, use
360360
if composition_integration:
361361
wsmean = np.mean(ws, axis=0)
362362
qsmean = np.mean(qs, axis=0)
363-
qsstd = np.mean(qs, axis=0)
364-
return wsmean, qsmean, qsstd, flambda
363+
wsstd = np.std(ws, axis=0)
364+
return wsmean, qsmean, wsstd, flambda
365365

366366
wsmean = np.mean(ws)
367367
qsmean = np.mean(qs)
368-
qsstd = np.mean(qs)
368+
wsstd = np.std(ws)
369369

370370
if full:
371-
return wsmean, qsmean, qsstd
371+
return wsmean, qsmean, wsstd
372372
else:
373373
return wsmean
374374

@@ -671,7 +671,10 @@ def integrate_mass(flambda, ref_mass, target_masses, target_counts,
671671
temperature, natoms):
672672

673673
mcorarr = np.zeros(len(flambda))
674+
mcorsum = 0
675+
674676
for i in range(len(target_masses)):
675677
mcorarr += 1.5*kb*temperature*(flambda*(target_counts[i]/natoms)*np.log(ref_mass/target_masses[i]))
676-
677-
return mcorarr
678+
mcorsum += 1.5*kb*temperature*(1.0*(target_counts[i]/natoms)*np.log(ref_mass/target_masses[i]))
679+
680+
return mcorarr, mcorsum

calphy/phase.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ def __repr__(self):
178178
data = self.calc.__repr__()
179179
return data
180180

181+
def _from_dict(self, org_dict, indict):
182+
for key, val in indict.items():
183+
if isinstance(val, dict):
184+
if key not in org_dict.keys():
185+
org_dict[key] = {}
186+
self._from_dict(org_dict[key], val)
187+
else:
188+
org_dict[key] = val
189+
181190
def prepare_lattice(self):
182191
"""
183192
Prepare the lattice for the simulation
@@ -564,13 +573,14 @@ def process_traj(self, filename, outfilename):
564573
os.remove(file)
565574

566575

567-
def submit_report(self):
576+
def submit_report(self, extra_dict=None):
568577
"""
569578
Submit final report containing results
570579
571580
Parameters
572581
----------
573-
None
582+
extra_dict: dict
583+
extra information to be written out
574584
575585
Returns
576586
-------
@@ -602,6 +612,10 @@ def submit_report(self):
602612
report["results"]["reference_system"] = float(self.fref)
603613
report["results"]["work"] = float(self.w)
604614
report["results"]["pv"] = float(self.pv)
615+
616+
if extra_dict is not None:
617+
self._from_dict(report, extra_dict)
618+
605619
self.report = report
606620

607621
reportfile = os.path.join(self.simfolder, "report.yaml")

calphy/routines.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,12 @@ def routine_composition_scaling(job):
514514
flambda_arr, w_arr, q_arr, qerr_arr = job.thermodynamic_integration()
515515

516516
#read the file
517-
mcorrarr = job.mass_integration(flambda_arr, ref_mass, target_masses, target_counts)
517+
mcorrarr, mcorsum = job.mass_integration(flambda_arr, ref_mass, target_masses, target_counts)
518518
netfe = w_arr - mcorrarr
519519

520+
job.fe = job.fe - mcorsum
521+
job.submit_report(extra_dict = {"results":{"mass_correction": float(mcorsum)}})
522+
520523
outfile = os.path.join(job.simfolder, "composition_sweep.dat")
521524
np.savetxt(outfile, np.column_stack((flambda_arr, netfe, w_arr, mcorrarr)))
522525
return job

docs/source/documentation/inputfile.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The inputfile is `yaml` formatted. In this section the possible keys in the inpu
1212
| [mode](#mode) | [lattice](#lattice) | [reference_phase](#reference_phase) | [temperature](#temperature) | [pressure](#pressure) |
1313
| [temperature_high](#temperature_high) | [lattice_constant](#lattice_constant) | [repeat](#repeat) | [n_iterations](#n_iterations) | [n_switching_steps](#n_switching_steps) |
1414
| [n_equilibration_steps](#n_equilibration_steps) | [pair_style](#pair_style) | [pair_coeff](#pair_coeff) | [n_print_steps](#n_print_steps) | [potential_file](#potential_file) |
15-
| [spring_constants](#spring_constants) | [equilibration_control](#equilibration_control) | [melting_cycle](#melting_cycle) | | |
15+
| [spring_constants](#spring_constants) | [equilibration_control](#equilibration_control) | [melting_cycle](#melting_cycle) | [folder_prefix](#folder_prefix) | |
1616

1717
| `md` block | | | | |
1818
| :-: | :-: | :-: | :-: | :-: |
@@ -32,6 +32,10 @@ The inputfile is `yaml` formatted. In this section the possible keys in the inpu
3232
| :-: | :-: | :-: | :-: | :-: |
3333
| [step](#step) | [attempts](#attempts) |
3434

35+
| `composition_scaling` block | | | | |
36+
| :-: | :-: | :-: | :-: | :-: |
37+
| [input_chemical_composition](#input_chemical_composition) | [output_chemical_composition](#output_chemical_composition) |
38+
3539
| `nose_hoover` block | | | | |
3640
| :-: | :-: | :-: | :-: | :-: |
3741
| [thermostat_damping](#nose_hoover_thermostat_damping) | [barostat_damping](#nose_hoover_barostat_damping) |
@@ -384,6 +388,20 @@ melting_cycle: False
384388

385389
If True, a melting cycle is carried out to melt the given input structure. Only used if the `reference_phase` is `"liquid"`.
386390

391+
392+
---
393+
394+
#### <a name="folder_prefix"></a>`folder_prefix`
395+
396+
_type_: string
397+
_default_: None
398+
_example_:
399+
```
400+
folder_prefix: set1
401+
```
402+
403+
Prefix string to be added to folder names for calculation. Folders for calculations in calphy are named as `mode-lattice-temperature-pressure`. Therefore, if more than one calculation is run with the same parameters, they will be overwritten. To prevent this, `folder_prefix` can be used. If `folder_prefix` is provided, the folders will be named as `folder_prefix-mode-lattice-temperature-pressure`.
404+
387405
---
388406
---
389407

@@ -731,6 +749,51 @@ The number of maximum attempts to try find the melting temperature in a automate
731749
---
732750
---
733751

752+
## `composition_scaling` block
753+
754+
This block contains keywords that are used only for the mode `composition_scaling`.
755+
756+
```
757+
composition_scaling:
758+
input_chemical_composition:
759+
- Cu: 512
760+
- Zr: 512
761+
output_chemical_composition:
762+
- Cu: 513
763+
- Zr: 511
764+
```
765+
766+
---
767+
768+
#### <a name="input_chemical_composition"></a>`input_chemical_composition`
769+
770+
_type_: list
771+
_example_:
772+
```
773+
input_chemical_composition:
774+
- Cu: 512
775+
- Zr: 512
776+
```
777+
778+
The input chemical composition in number of atoms. It should be identical to the input structure provided.
779+
780+
---
781+
782+
#### <a name="output_chemical_composition"></a>`output_chemical_composition`
783+
784+
_type_: list
785+
_example_:
786+
```
787+
output_chemical_composition:
788+
- Cu: 513
789+
- Zr: 511
790+
```
791+
792+
The output chemical composition in number of atoms. The total number of atoms should be equal to the input provided.
793+
794+
---
795+
---
796+
734797

735798
## <a name="nose_hoover"></a>`nose_hoover` block
736799

docs/source/examples.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Examples
1212
examples/example_07/analysis
1313
examples/example_08/analysis
1414
examples/example_09/analysis
15+
examples/example_10/analysis

environment-nolammps.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ dependencies:
1515
- pyscal
1616
- matplotlib
1717
- tqdm
18+
- uncertainties

0 commit comments

Comments
 (0)