Skip to content

Commit 63565d1

Browse files
authored
Merge pull request #159 from ICAMS/update_cm_correction
Update cm correction
2 parents bb2f76b + 5593b90 commit 63565d1

File tree

8 files changed

+87
-42
lines changed

8 files changed

+87
-42
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.3.10
2+
current_version = 1.3.11
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.3.10"
7+
__version__ = "1.3.11"
88

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

calphy/input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from ase.io import read, write
4141
import shutil
4242

43-
__version__ = "1.3.10"
43+
__version__ = "1.3.11"
4444

4545
def _check_equal(val):
4646
if not (val[0]==val[1]==val[2]):

calphy/integrators.py

Lines changed: 68 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@
3838

3939
#Constants
4040
h = const.physical_constants["Planck constant in eV/Hz"][0]
41+
hJ = const.physical_constants["Planck constant"][0]
4142
hbar = h/(2*np.pi)
4243
kb = const.physical_constants["Boltzmann constant in eV/K"][0]
4344
kbJ = const.physical_constants["Boltzmann constant"][0]
4445
Na = const.physical_constants["Avogadro constant"][0]
4546
eV2J = const.eV
46-
47+
J2eV = 6.242E18
4748

4849
#--------------------------------------------------------------------
4950
# TI PATH INTEGRATION ROUTINES
@@ -469,64 +470,96 @@ def get_einstein_crystal_fe(
469470
calc,
470471
vol,
471472
k,
472-
cm_correction=True):
473+
cm_correction=True,
474+
return_contributions=False):
473475
"""
474476
Get the free energy of einstein crystal
475477
476478
Parameters
477479
----------
478-
temp : temperature, float
479-
units - K
480-
481-
natoms : int
482-
no of atoms in the system
483-
484-
mass : float
485-
units - g/mol
480+
calc : Calculation object
481+
contains all input parameters
486482
487-
a : lattice constant, float
488-
units - Angstrom
483+
vol : float
484+
converged volume per atom
489485
490486
k : spring constant, float
491487
units - eV/Angstrom^2
492488
493489
cm_correction : bool, optional, default - True
494490
add the centre of mass correction to free energy
495491
492+
return_contributions: bool, optional, default - True
493+
If True, return individual contributions to the reference free energy.
494+
496495
Returns
497496
-------
498-
fe : float
499-
free energy of Einstein crystal
497+
F_tot : float
498+
total free energy of reference crystal
499+
500+
F_e : float
501+
Free energy of Einstein crystal without centre of mass correction. Only if `return_contributions` is True.
502+
503+
F_cm : float
504+
centre of mass correction. Only if `return_contributions` is True.
505+
506+
Notes
507+
-----
508+
The equations for free energy of Einstein crystal and centre of mass correction are from https://doi.org/10.1063/5.0044833.
500509
501510
"""
502-
#convert mass first for single particle in kg
503-
mass = np.array([calc._element_dict[x]['mass'] for x in calc.element])
504-
mass = (mass/Na)*1E-3
505-
natoms = np.sum([calc._element_dict[x]['count'] for x in calc.element])
506-
concentration = np.array([calc._element_dict[x]['composition'] for x in calc.element])
511+
#temperature
512+
temp = calc._temperature
507513

508-
#convert k from ev/A2 to J/m2
509-
k = np.array(k)*(eV2J/1E-20)
510-
omega = np.sqrt(k/mass)
514+
#natoms
515+
natoms = np.sum([calc._element_dict[x]['count'] for x in calc.element])
511516

512517
#convert a to m3
513518
vol = vol*1E-30
514519

515-
F_harm = 0
516-
F_cm = 0
520+
#whats the beta
521+
beta = (1/(kbJ*temp))
517522

518-
for count, om in enumerate(omega):
519-
if concentration[count] > 0:
520-
F_harm += concentration[count]*np.log((hbar*om)/(kb*calc._temperature))
521-
if cm_correction:
522-
F_cm += np.log((natoms*concentration[count]/vol)*(2*np.pi*kbJ*calc._temperature/(natoms*concentration[count]*k[count]))**1.5)
523-
#F_cm = 0
524-
F_harm = 3*kb*calc._temperature*F_harm
525-
F_cm = (kb*calc._temperature/natoms)*F_cm
526-
527-
F_harm = F_harm + F_cm
523+
#create an array of mass
524+
mass = []
525+
for x in calc.element:
526+
for count in range(calc._element_dict[x]['count']):
527+
mass.append(calc._element_dict[x]['mass'])
528+
mass = np.array(mass)
529+
530+
#convert mass to kg
531+
mass = (mass/Na)*1E-3
528532

529-
return F_harm
533+
#create an array of k as well
534+
karr = []
535+
for c, x in enumerate(calc.element):
536+
for count in range(calc._element_dict[x]['count']):
537+
karr.append(k[c])
538+
k = np.array(karr)
539+
#convert k from ev/A2 to J/m2
540+
k = k*(eV2J/1E-20)
541+
542+
#fe of Einstein crystal
543+
Z_e = ((beta**2*k*hJ**2)/(4*np.pi**2*mass))**1.5
544+
F_e = np.log(Z_e)
545+
F_e = kb*temp*np.sum(F_e)/natoms #*J2eV #convert back to eV
546+
547+
#now get the cm correction
548+
if cm_correction:
549+
mass_sum = np.sum(mass)
550+
mu = mass/mass_sum
551+
mu2_over_k = mu**2/k
552+
mu2_over_k_sum = np.sum(mu2_over_k)
553+
prefactor = vol
554+
F_cm = np.log(prefactor*(beta/(2*np.pi*mu2_over_k_sum))**1.5)
555+
F_cm = kb*temp*F_cm/natoms #convert to eV
556+
else:
557+
F_cm = 0
558+
559+
F_tot = F_e - F_cm
560+
if return_contributions:
561+
return F_e, -F_cm
562+
return F_tot
530563

531564
#--------------------------------------------------------------------
532565
# REF. STATE ROUTINES: LIQUID

calphy/phase.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ def __init__(self, calculation=None, simfolder=None, log_to_screen=False):
163163

164164
self.ferr = 0
165165
self.fref = 0
166+
self.feinstein = 0
167+
self.fcm = 0
166168
self.fideal = 0
167169

168170
self.w = 0
@@ -682,6 +684,8 @@ def submit_report(self, extra_dict=None):
682684
report["results"]["free_energy"] = float(self.fe)
683685
report["results"]["error"] = float(self.ferr)
684686
report["results"]["reference_system"] = float(self.fref)
687+
report["results"]["einstein_crystal"] = float(self.feinstein)
688+
report["results"]["com_correction"] = float(self.fcm)
685689
report["results"]["work"] = float(self.w)
686690
report["results"]["pv"] = float(self.pv)
687691
report["results"]["unit"] = "eV/atom"

calphy/solid.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,17 +516,20 @@ def thermodynamic_integration(self):
516516
Calculates the final work, energy dissipation and free energy by
517517
matching with Einstein crystal
518518
"""
519-
f1 = get_einstein_crystal_fe(
519+
fe, fcm = get_einstein_crystal_fe(
520520
self.calc,
521521
self.vol,
522-
self.k)
522+
self.k,
523+
return_contributions=True)
523524

524525
w, q, qerr = find_w(self.simfolder,
525526
self.calc,
526527
full=True,
527528
solid=True)
528529

529-
self.fref = f1
530+
self.fref = fe + fcm
531+
self.feinstein = fe
532+
self.fcm = fcm
530533
self.w = w
531534
self.ferr = qerr
532535

docs/source/prologue/acknowledgements.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ We acknowledge the following people for their contribution to calphy:
2424

2525
- Abril Azócar Guzmán for the design of calphy logo
2626

27+
- Marvin Poul for numerous fixes, improvements, and for the help in fixing centre of mass corrections for multiple species
28+
29+
- Sebastian Havens for the singularity recipe
30+
31+
2732
The development of this module was started at the [Interdisciplinary Centre for Advanced
2833
Materials Simulation](http://www.icams.de/content), at the [Ruhr
2934
University Bochum](https://www.ruhr-uni-bochum.de/en), Germany. Current development is carried out at the [Max-Planck-Institut für Eisenforschung GmbH](https://www.mpie.de/).

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
packages=find_packages(include=['calphy', 'calphy.*']),
5454
test_suite='tests',
5555
url='https://github.com/ICAMS/calphy',
56-
version='1.3.10',
56+
version='1.3.11',
5757
zip_safe=False,
5858
entry_points={
5959
'console_scripts': [

0 commit comments

Comments
 (0)