Skip to content

Commit

Permalink
Cleanup lobserter.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed Jul 25, 2020
1 parent ef37cd2 commit e5c7c63
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 125 deletions.
22 changes: 9 additions & 13 deletions pymatgen/io/exciting/inputs.py
Expand Up @@ -6,19 +6,16 @@
Classes for reading/manipulating/writing exciting input files.
"""

import numpy as np

from monty.io import zopen

import xml.etree.cElementTree as ET

import numpy as np
import scipy.constants as const
from monty.io import zopen
from monty.json import MSONable

from pymatgen.core.lattice import Lattice
from pymatgen.core.structure import Structure
from pymatgen.core.periodic_table import Element
from monty.json import MSONable

from pymatgen.core.structure import Structure
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from pymatgen.symmetry.bandstructure import HighSymmKpath

Expand Down Expand Up @@ -117,7 +114,7 @@ def from_string(data):
if atom.get('lockxyz') is not None:
lxyz = []
for l in atom.get('lockxyz').split():
if l == 'True' or l == 'true':
if l in ('True', 'true'):
lxyz.append(True)
else:
lxyz.append(False)
Expand All @@ -128,9 +125,9 @@ def from_string(data):
if 'cartesian' in root.find('structure').attrib.keys():
if root.find('structure').attrib['cartesian']:
cartesian = True
for i in range(len(positions)):
for i, p in enumerate(positions):
for j in range(3):
positions[i][j] = positions[i][j] * ExcitingInput.bohr2ang
p[j] = p[j] * ExcitingInput.bohr2ang
print(positions)
else:
cartesian = False
Expand Down Expand Up @@ -295,7 +292,6 @@ def write_file(self, celltype, filename, cartesian=False, bandstr=False, symprec
tree.write(filename)
except Exception:
raise ValueError('Incorrect celltype!')
return

# Missing PrerryPrint option in the current version of xml.etree.cElementTree
@staticmethod
Expand All @@ -313,8 +309,8 @@ def indent(elem, level=0):
elem.text = i + " "
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
ExcitingInput.indent(elem, level + 1)
for el in elem:
ExcitingInput.indent(el, level + 1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/lobster/__init__.py
Expand Up @@ -11,4 +11,4 @@
"""

from .inputs import Lobsterin
from .outputs import Cohpcar, Icohplist, Doscar, Charge, Lobsterout, Fatband, Bandoverlaps, Grosspop
from .outputs import Cohpcar, Icohplist, Doscar, Charge, Lobsterout, Fatband, Bandoverlaps, Grosspop
42 changes: 20 additions & 22 deletions pymatgen/io/lobster/inputs.py
Expand Up @@ -99,7 +99,7 @@ def __setitem__(self, key, val):
if not found:
new_key = key
if new_key.lower() not in [element.lower() for element in Lobsterin.AVAILABLEKEYWORDS]:
raise (ValueError("Key is currently not available"))
raise ValueError("Key is currently not available")

super().__setitem__(new_key, val.strip() if isinstance(val, str) else val)

Expand Down Expand Up @@ -147,8 +147,8 @@ def diff(self, other):
else:
similar_param[k1.upper()] = v1
elif isinstance(v1, list):
new_set1 = set([element.strip().lower() for element in v1])
new_set2 = set([element.strip().lower() for element in other[new_key]])
new_set1 = {element.strip().lower() for element in v1}
new_set2 = {element.strip().lower() for element in other[new_key]}
if new_set1 != new_set2:
different_param[k1.upper()] = {"lobsterin1": v1, "lobsterin2": other[new_key]}
else:
Expand All @@ -174,15 +174,15 @@ def _get_nbands(self, structure: Structure):
"""
if self.get("basisfunctions") is None:
raise IOError("No basis functions are provided. The program cannot calculate nbands.")
else:
basis_functions = [] # type: List[str]
for string_basis in self["basisfunctions"]:
# string_basis.lstrip()
string_basis_raw = string_basis.strip().split(" ")
while "" in string_basis_raw:
string_basis_raw.remove("")
for i in range(0, int(structure.composition.element_composition[string_basis_raw[0]])):
basis_functions.extend(string_basis_raw[1:])

basis_functions = [] # type: List[str]
for string_basis in self["basisfunctions"]:
# string_basis.lstrip()
string_basis_raw = string_basis.strip().split(" ")
while "" in string_basis_raw:
string_basis_raw.remove("")
for i in range(0, int(structure.composition.element_composition[string_basis_raw[0]])):
basis_functions.extend(string_basis_raw[1:])

no_basis_functions = 0
for basis in basis_functions:
Expand Down Expand Up @@ -212,10 +212,10 @@ def write_lobsterin(self, path="lobsterin", overwritedict=None):
found = False
for key2 in self.keys():
if key.lower() == key2.lower():
self.get[key2] = entry
self[key2] = entry
found = True
if not found:
self.get[key] = entry
self[key] = entry

filename = path
with open(filename, 'w') as f:
Expand Down Expand Up @@ -298,7 +298,7 @@ def get_basis(structure: Structure, potcar_symbols: list,
Returns:
returns basis
"""
Potcar_names = [name for name in potcar_symbols]
Potcar_names = list(potcar_symbols)

AtomTypes_Potcar = [name.split('_')[0] for name in Potcar_names]

Expand Down Expand Up @@ -338,7 +338,7 @@ def get_all_possible_basis_functions(structure: Structure,
address_basis_file_min: path to file with the minium required basis by the POTCAR
address_basis_file_max: path to file with the largest possible basis of the POTCAR
Returns: List of dictionaries that can be used to create new Lobsterin objects in
Returns: List of dictionaries that can be used to create new Lobsterin objects in
standard_calculations_from_vasp_files as dict_for_basis
"""
Expand Down Expand Up @@ -474,8 +474,8 @@ def write_KPOINTS(POSCAR_input: str = "POSCAR", KPOINTS_output="KPOINTS.lobster"
line_density=kpoints_line_density,
coords_are_cartesian=False)

for k in range(len(frac_k_points)):
kpts.append(frac_k_points[k])
for k, f in enumerate(frac_k_points):
kpts.append(f)
weights.append(0.0)
all_labels.append(labels[k])
if isym == -1:
Expand Down Expand Up @@ -701,13 +701,11 @@ def get_all_possible_basis_combinations(min_basis: list, max_basis: list) -> lis
for iel, el in enumerate(list_basis[1:], 1):
new_start_basis = []
for ielbasis, elbasis in enumerate(start_basis):

for ielbasis2, elbasis2 in enumerate(list_basis[iel]):
if type(elbasis) != list:
if not isinstance(elbasis, list):
new_start_basis.append([elbasis, elbasis2])
else:
new_start_basis.append(elbasis.copy() + [elbasis2])
start_basis = new_start_basis
return start_basis
else:
return [[basis] for basis in start_basis]
return [[basis] for basis in start_basis]

0 comments on commit e5c7c63

Please sign in to comment.