Skip to content

Commit

Permalink
Add abi_kwargs kwargs to new_with_structure
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatteo committed Nov 15, 2024
1 parent 07687dd commit 7331b76
Show file tree
Hide file tree
Showing 16 changed files with 934 additions and 237 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }}

steps:
- name: Check out Abipy repo
- name: Checkout Abipy repo
uses: actions/checkout@v4

- name: Set up Miniconda
Expand Down
25 changes: 16 additions & 9 deletions abipy/abio/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def runlevel(self):
# DTE run.
runlevel.add(atags.DFPT)
runlevel.add(atags.DTE)

elif optdriver == 99:
# BSE run
runlevel.update([atags.MANY_BODY, atags.BSE])
Expand Down Expand Up @@ -1502,7 +1502,7 @@ def new_with_vars(self, *args, **kwargs) -> AbinitInput:
new.set_vars(*args, **kwargs)
return new

def new_with_structure(self, new_structure, scdims=None, verbose=1) -> AbinitInput:
def new_with_structure(self, new_structure, scdims=None, verbose=1, **abi_vars) -> AbinitInput:
"""
Return a new |AbinitInput| with a different structure.
See notes below for the constraints that must be fulfilled by the new structure
Expand All @@ -1514,6 +1514,7 @@ def new_with_structure(self, new_structure, scdims=None, verbose=1) -> AbinitInp
Must be used when `new_structure` represents a supercell of the initial structure defined
in the input file.
verbose: Verbosity level.
abi_vars: Abinit variables added to the Abinit input.
.. warning::
Expand All @@ -1522,11 +1523,15 @@ def new_with_structure(self, new_structure, scdims=None, verbose=1) -> AbinitInp
When structure represents a supercell, `scdims` must be coherent with the `new_structure` passed
as argument.
"""
new_structure = Structure.as_structure(new_structure)

# Check structure
if scdims is None:
# Assume same value of natom and typat
if len(self.structure) != len(new_structure):
raise ValueError("Structures must have same value of natom")
raise ValueError(f"Structures must have same value of natom." +
f"new_structure has {len(new_structure)} atoms." +
f"input.structure has {len(self.structure)}")
errors = []
for i, (site1, site2) in enumerate(zip(self.structure, new_structure)):
if site1.specie.symbol != site2.specie.symbol:
Expand Down Expand Up @@ -1610,6 +1615,8 @@ def new_with_structure(self, new_structure, scdims=None, verbose=1) -> AbinitInp
# Add chkprim if not yet done.
new.set_vars_ifnotin(chkprim=0)

new.set_vars(**abi_vars)

return new

def new_with_decorators(self, decorators) -> AbinitInput:
Expand Down Expand Up @@ -1929,7 +1936,7 @@ def make_ph_inputs_qpoint(self, qpt, tolerance=None,
def make_ddkpert_input(self, perturbation, kptopt=2, only_vk=False, use_symmetries=False, tolerance=None, manager=None) -> AbinitInput:
"""
Returns |AbinitInput| for the calculation of an electric field perturbation.
This function should be called with an input that represents a GS run and
This function should be called with an input that represents a GS run and
an electric field perturbation.
Args:
Expand Down Expand Up @@ -1973,7 +1980,7 @@ def make_ddkpert_input(self, perturbation, kptopt=2, only_vk=False, use_symmetri

if only_vk:
inp.set_vars(nstep=1, nline=1)

# TODO: to implement
#if not use_symmetries:
# inp.set_vars(
Expand Down Expand Up @@ -2073,11 +2080,11 @@ def make_dkdk_input(self, tolerance=None, kptopt=2, manager=None) -> AbinitInput
dkdk_input.set_vars(tolerance)

return dkdk_input

def make_ddepert_input(self, perturbation, use_symmetries=True, tolerance=None, manager=None) -> AbinitInput:
"""
Returns |AbinitInput| for the calculation of an electric field perturbation.
This function should be called with an input that represents a GS run and
This function should be called with an input that represents a GS run and
an electric field perturbation.
Args:
Expand Down Expand Up @@ -2111,7 +2118,7 @@ def make_ddepert_input(self, perturbation, use_symmetries=True, tolerance=None,
qpt=(0, 0, 0), # q-wavevector.
kptopt=2, # Take into account time-reversal symmetry.
)

if not use_symmetries:
inp.set_vars(
comment="Input file for DDE calculation without symmetries.",
Expand All @@ -2122,7 +2129,7 @@ def make_ddepert_input(self, perturbation, use_symmetries=True, tolerance=None,
inp.set_vars(tolerance)

return inp

def make_dde_inputs(self, tolerance=None, use_symmetries=True, manager=None) -> MultiDataset:
"""
Return |MultiDataset| inputs for the calculation of electric field perturbations.
Expand Down
34 changes: 17 additions & 17 deletions abipy/dfpt/deformation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def generate_deformations_volumic(structure, eps_V=0.02, scales=None):

return structures_new

def generate_deformations(structure , eps=0.005):
spgrp = AbinitSpaceGroup.from_structure(structure )
def generate_deformations(structure, eps=0.005):
spgrp = AbinitSpaceGroup.from_structure(structure )
print (spgrp)
spgrp_number=spgrp.spgid
rprim= structure.lattice.matrix
Expand All @@ -39,11 +39,11 @@ def generate_deformations(structure , eps=0.005):
structures_new = {}

if 1 <= spgrp_number <= 2:
disp=[[1,1,1,1,1,1], [0,1,1,1,1,1], [2,1,1,1,1,1], [1,0,1,1,1,1], [1,2,1,1,1,1], [1,1,0,1,1,1],
[1,1,2,1,1,1], [1,1,1,0,1,1], [1,1,1,2,1,1], [1,1,1,1,0,1], [1,1,1,1,2,1], [1,1,1,1,1,0],
[1,1,1,1,1,2], [0,0,1,1,1,1], [1,0,0,1,1,1], [1,1,0,0,1,1], [1,1,1,0,0,1], [1,1,1,1,0,0],
[0,1,0,1,1,1], [0,1,1,0,1,1], [0,1,1,1,0,1], [0,1,1,1,1,0], [1,0,1,0,1,1], [1,0,1,1,0,1],
[1,0,1,1,1,0], [1,1,0,1,0,1], [1,1,0,1,1,0], [1,1,1,0,1,0] , [0 ,0,0,0,0,0]]
disp=[[1,1,1,1,1,1], [0,1,1,1,1,1], [2,1,1,1,1,1], [1,0,1,1,1,1], [1,2,1,1,1,1], [1,1,0,1,1,1],
[1,1,2,1,1,1], [1,1,1,0,1,1], [1,1,1,2,1,1], [1,1,1,1,0,1], [1,1,1,1,2,1], [1,1,1,1,1,0],
[1,1,1,1,1,2], [0,0,1,1,1,1], [1,0,0,1,1,1], [1,1,0,0,1,1], [1,1,1,0,0,1], [1,1,1,1,0,0],
[0,1,0,1,1,1], [0,1,1,0,1,1], [0,1,1,1,0,1], [0,1,1,1,1,0], [1,0,1,0,1,1], [1,0,1,1,0,1],
[1,0,1,1,1,0], [1,1,0,1,0,1], [1,1,0,1,1,0], [1,1,1,0,1,0] , [0 ,0,0,0,0,0]]
if abs(rprim[1, 0]) > 1e-9 or abs(rprim[2, 0]) > 1e-9 or abs(rprim[2, 1]) > 1e-9:
print("Warning: The lattice is oriented such that xz =xy =yz =0 .")
rprim0 = np.copy(rprim)
Expand All @@ -59,12 +59,12 @@ def generate_deformations(structure , eps=0.005):
cos_ac = np.dot(a, c) / (norm_a * norm_c)
cos_bc = np.dot(b, c) / (norm_b * norm_c)

rprim0[0,0] = 1.0
rprim0[0,1] = 0.0
rprim0[0,2] = 0.0
rprim0[0,0] = 1.0
rprim0[0,1] = 0.0
rprim0[0,2] = 0.0
rprim0[1,0] = cos_ab
rprim0[1,1] = np.sqrt(1-cos_ab**2)
rprim0[1,2] = 0.0
rprim0[1,2] = 0.0
rprim0[2,0] = cos_ac
rprim0[2,1] = (cos_bc-rprim0[1,0]*rprim0[2,0])/rprim0[1,1]
rprim0[2,2] = np.sqrt(1.0-rprim0[2,0]**2-rprim0[2,1]**2)
Expand Down Expand Up @@ -92,7 +92,7 @@ def generate_deformations(structure , eps=0.005):

structure2=structure.copy()
structure2.lattice=Lattice(rprim2)
structures_new[formatted_namei] = structure2
structures_new[formatted_namei] = structure2

return structures_new
elif 3 <= spgrp_number <= 15:
Expand All @@ -116,7 +116,7 @@ def generate_deformations(structure , eps=0.005):
cos_bc = np.dot(b, c) / (norm_b * norm_c)

rprim0[0,0] = norm_a
rprim0[0,2] = 0.0
rprim0[0,2] = 0.0
rprim0[1,1] = norm_b
rprim0[2,0] = norm_c*cos_ac
rprim0[2,2] = norm_c*np.sqrt(1-cos_ac**2)
Expand All @@ -139,7 +139,7 @@ def generate_deformations(structure , eps=0.005):

structure2=structure.copy()
structure2.lattice=Lattice(rprim2)
structures_new[formatted_namei] = structure2
structures_new[formatted_namei] = structure2

return structures_new
elif 16 <= spgrp_number <= 74:
Expand All @@ -157,7 +157,7 @@ def generate_deformations(structure , eps=0.005):

structure2=structure.copy()
structure2.lattice=Lattice(rprim2)
structures_new[formatted_namei] = structure2
structures_new[formatted_namei] = structure2

return structures_new
elif 75 <= spgrp_number <= 194:
Expand All @@ -175,7 +175,7 @@ def generate_deformations(structure , eps=0.005):

structure2=structure.copy()
structure2.lattice=Lattice(rprim2)
structures_new[formatted_namei] = structure2
structures_new[formatted_namei] = structure2

return structures_new
elif 195 <= spgrp_number <= 230:
Expand All @@ -188,6 +188,6 @@ def generate_deformations(structure , eps=0.005):

structure2=structure.copy()
structure2.lattice=Lattice(rprim2)
structures_new[formatted_namei] = structure2
structures_new[formatted_namei] = structure2
return structures_new

Loading

0 comments on commit 7331b76

Please sign in to comment.