Skip to content

Commit

Permalink
Code cleanup in qha_aproximation.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatteo committed Dec 14, 2024
1 parent 916dfbb commit 2c53c9a
Show file tree
Hide file tree
Showing 11 changed files with 323 additions and 455 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ abinit_vars.pickle
Profile.prof
abipy/examples/flows/flow_*
abipy/examples/flows/develop/flow_*
__abipy_import.log
_debug
abipy/scripts/tests/test-output/
#__abinb_workdir__
#abinb_*.ipynb
$*.pickle
Expand Down
504 changes: 247 additions & 257 deletions abipy/dfpt/qha_aproximation.py

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions abipy/dfpt/tests/test_qha_approximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,20 @@ def test_v_ZSIZA(self):
self.assert_almost_equal(data.min_vol, 40.05665096)
self.assert_almost_equal(data.temp, 0)

e2d_v = qha.second_derivative_energy_v(41)
self.assert_almost_equal(e2d_v, 0.0128727)

f = qha.get_thermal_expansion_coeff(tstart=0, tstop=1000, num=7, tref=None)
self.assert_almost_equal(f.values, [-0.0000000e+00, 5.1944952e-07, 7.0431284e-06, 9.4401141e-06,
1.0630764e-05, 1.1414897e-05, 1.2035432e-05])

vols, fits = qha.vol_Einf_Vib4(num=2, tstop=tstop, tstart=tstart)
aas, bbs, ccs = qha.get_abc(tstart=tstart, tstop=tstop, num=2, volumes=vols)
aas, bbs, ccs = qha.get_abc(volumes=vols, num=2)
self.assert_almost_equal(aas, [3.8466098, 3.8530056])
self.assert_almost_equal(bbs, [3.8466098, 3.8530056])
self.assert_almost_equal(ccs, [3.8466098, 3.8530056])

alphas, betas, gammas = qha.get_angles(tstart=tstart, tstop=tstop, num=2, volumes=vols)
alphas, betas, gammas = qha.get_angles(vols, num=2)
self.assert_almost_equal(alphas, [60., 60.])
self.assert_almost_equal(betas, [60., 60.])
self.assert_almost_equal(gammas, [60., 60.])
Expand Down
13 changes: 6 additions & 7 deletions abipy/embedding/tests/test_embedding_ifc.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ def test_embedding_interstitial(self):
########
### model of the split-interstitial as one vacancy + 2 inter.

stru=abiopen(abidata.ref_file("refs/embedding_ifc/C_sc.cif"))
stru= abiopen(abidata.ref_file("refs/embedding_ifc/C_sc.cif"))
stru.remove_sites(indices=[14])
stru.append(species="C",coords=[0.600, 0.5000, 0.2500])
stru.append(species="C",coords=[0.400, 0.5000, 0.2500])
structure_defect_wo_relax=stru
stru.append(species="C", coords=[0.600, 0.5000, 0.2500])
stru.append(species="C", coords=[0.400, 0.5000, 0.2500])
structure_defect_wo_relax = stru

# main defect is
main_defect_coords_in_pristine=get_pmg_structure(ph_pristine.supercell)[31].coords
Expand All @@ -184,8 +184,7 @@ def test_embedding_interstitial(self):


freqs, vecs = ph_emb.get_gamma_freq_with_vec_abipy_fmt()

self.assert_almost_equal(freqs[-1],0.212826358519,decimal=5)
self.assert_almost_equal(freqs[-1], 0.212826358519, decimal=5)

ratio = localization_ratio(vecs)
self.assert_almost_equal(ratio[650],78.76445591,decimal=5)
self.assert_almost_equal(ratio[650], 78.76445591, decimal=5)
12 changes: 12 additions & 0 deletions abipy/scripts/abiview.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ def abiview_structure(options):
return 0


def abiview_input(options):
"""Read input file from netcdf file and print it to terminal."""
from abipy.iotools import ETSF_Reader
with ETSF_Reader(options.filepath) as r:
input_str = r.read_string("input_string")
print(input_str)
return 0


def abiview_hist(options):
"""
Visualize structural relaxation/molecular-dynamics run
Expand Down Expand Up @@ -701,6 +710,9 @@ def add_args(p, *args):
help=("Application name. Default: vesta. "
"Possible options: %s, mayavi, vtk" % ", ".join(Visualizer.all_visunames())))

# Subparser for input command.
p_input = subparsers.add_parser('input', parents=[copts_parser], help=abiview_input.__doc__)

# Subparser for hist command.
p_hist = subparsers.add_parser('hist', parents=[copts_parser], help=abiview_hist.__doc__)
p_hist.add_argument("-a", "--appname", nargs="?", default=None, const="ovito",
Expand Down
104 changes: 0 additions & 104 deletions dev_scripts/mlrun.py

This file was deleted.

48 changes: 0 additions & 48 deletions dev_scripts/pyclean.py

This file was deleted.

3 changes: 0 additions & 3 deletions dev_scripts/run_tuna.sh

This file was deleted.

31 changes: 0 additions & 31 deletions dev_scripts/runtests.sh

This file was deleted.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ dependencies = [
"numpy<2.0.0",
"packaging",
"pandas",
"phonopy",
"phonopy<=2.31.2",
"plotly",
"pydispatcher>=2.0.5",
"pymatgen>=2022.0.14",
"pymatgen==v2024.10.29",
"monty==v2024.10.21",
"pyyaml>=3.11",
"scipy",
"seaborn",
Expand Down
49 changes: 48 additions & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Deployment file to facilitate AbiPy releases.
Use invoke --list to get list of tasks
"""

import os
import shutil

from invoke import task
from monty.os import cd
Expand Down Expand Up @@ -128,6 +128,53 @@ def update_vars(ctx, abinit_repo_path):
os.system(cmd)


@task
def pyclean(ctx):
"""remove all pyc files and all __pycache__ directory."""

def rm_pycaches(top: str) -> None:
"""remove __pycache__ directory."""
count = 0
for dirpath, dirnames, filenames in os.walk(top):
for d in dirnames:
if not d == "__pycache__": continue
path = os.path.join(dirpath, d)
#print("Will remove %s" % path)
shutil.rmtree(path)
count += 1

print("Removed %d __pycache__ directories" % count)


def rm_pycfiles(top: str) -> int:
"""remove all pyc files."""
count = 0
for dirpath, dirnames, filenames in os.walk(top):
for f in filenames:
if not f.endswith(".pyc"): continue
path = os.path.join(dirpath, f)
#print("Will remove %s" % path)
os.remove(path)
count += 1

print("Removed %d .pyc files" % count)
return count

top = ABIPY_ROOTDIR
rm_pycaches(top)
rm_pycfiles(top)


@task
def tuna(ctx):
"""Execute tuna import profiler."""
cmd = 'python -X importtime -c "import abipy" 2> __abipy_import.log'
print("Executing:", cmd)
ctx.run(cmd, pty=True)
cmd = "tuna __abipy_import.log"
ctx.run(cmd, pty=True)


#@task
#def move_to_master(ctx):
# ctx.run("git tag -a v%s -m \"v%s release\"" % (NEW_VER, NEW_VER))
Expand Down

0 comments on commit 2c53c9a

Please sign in to comment.