Skip to content

Commit

Permalink
breaking: snake_case method names
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Oct 3, 2023
1 parent 679fe1c commit 2a43d25
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 73 deletions.
8 changes: 4 additions & 4 deletions pymatgen/io/fiesta.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def set_auxiliary_basis_set(self, folder, auxiliary_folder, auxiliary_basis_set_
if file.upper().find(specie.upper() + "2") != -1 and file.lower().find(auxiliary_basis_set_type) != -1:
shutil.copyfile(auxiliary_folder + "/" + file, folder + "/" + specie + "2.ion")

def set_GW_options(self, nv_band=10, nc_band=10, n_iteration=5, n_grid=6, dE_grid=0.5):
def set_gw_options(self, nv_band=10, nc_band=10, n_iteration=5, n_grid=6, dE_grid=0.5):
"""
Set parameters in cell.in for a GW computation
:param nv__band: number of valence bands to correct with GW
Expand All @@ -359,15 +359,15 @@ def set_GW_options(self, nv_band=10, nc_band=10, n_iteration=5, n_grid=6, dE_gri
self.correlation_grid.update(dE_grid=dE_grid, n_grid=n_grid)

@staticmethod
def make_FULL_BSE_Densities_folder(folder):
def make_full_bse_densities_folder(folder):
"""Mkdir "FULL_BSE_Densities" folder (needed for bse run) in the desired folder."""
if os.path.exists(folder + "/FULL_BSE_Densities"):
return "FULL_BSE_Densities folder already exists"

os.makedirs(folder + "/FULL_BSE_Densities")
return "makedirs FULL_BSE_Densities folder"

def set_BSE_options(self, n_excitations=10, nit_bse=200):
def set_bse_options(self, n_excitations=10, nit_bse=200):
"""
Set parameters in cell.in for a BSE computation
:param nv_bse: number of valence bands
Expand All @@ -377,7 +377,7 @@ def set_BSE_options(self, n_excitations=10, nit_bse=200):
"""
self.BSE_TDDFT_options.update(npsi_bse=n_excitations, nit_bse=nit_bse)

def dump_BSE_data_in_GW_run(self, BSE_dump=True):
def dump_bse_data_in_gw_run(self, BSE_dump=True):
"""
:param BSE_dump: boolean
Expand Down
10 changes: 2 additions & 8 deletions pymatgen/io/qchem/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import copy
import re
from collections import defaultdict

Expand Down Expand Up @@ -204,19 +203,14 @@ def process_parsed_fock_matrix(fock_matrix):
return fock_matrix_reshaped


def process_parsed_HESS(hess_data):
def process_parsed_hess(hess_data):
"""
Takes the information contained in a HESS file and converts it into
the format of the machine-readable 132.0 file which can be printed
out to be read into subsequent optimizations.
"""
dim = int(hess_data[1].split()[1])
hess = []
tmp_part = []
for _ii in range(dim):
tmp_part.append(0.0)
for _ii in range(dim):
hess.append(copy.deepcopy(tmp_part))
hess = [[0 for _ in range(dim)] for _ in range(dim)]

row = 0
column = 0
Expand Down
10 changes: 5 additions & 5 deletions pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4881,7 +4881,7 @@ def from_binary(cls, filename, data_type="complex64"):
"""
with open(filename, "rb") as fp:

def readData(dtype):
def read_data(dtype):
"""Read records from Fortran binary file and convert to np.array of given dtype."""
data = b""
while True:
Expand All @@ -4896,11 +4896,11 @@ def readData(dtype):
break
return np.frombuffer(data, dtype=dtype)

nbands, nelect, nk, ispin = readData(np.int32)
_ = readData(np.float_) # nodes_in_dielectric_function
_ = readData(np.float_) # wplasmon
nbands, nelect, nk, ispin = read_data(np.int32)
_ = read_data(np.float_) # nodes_in_dielectric_function
_ = read_data(np.float_) # wplasmon
me_datatype = np.dtype(data_type)
cder = readData(me_datatype)
cder = read_data(me_datatype)

cder_data = cder.reshape((3, ispin, nk, nelect, nbands)).T
return cls(cder_data.real, cder_data.imag)
Expand Down
58 changes: 15 additions & 43 deletions pymatgen/symmetry/kpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ def _get_ksymm_kpath(self, has_magmoms, magmom_axis, axis_specified, symprec, an

# Calculate cosine values for all 26 neighbor points
for point_index in range(26):
label_point = self.LabelPoints(point_index)
label_point = self.label_points(point_index)

# Calculate cosine of angle between key_point and label_point
cosine_value = np.dot(key_point, label_point)
Expand All @@ -1271,7 +1271,7 @@ def _get_ksymm_kpath(self, has_magmoms, magmom_axis, axis_specified, symprec, an
key_points_labels = ["" for i in range(len(key_points))]
for idx, orbit in enumerate(key_points_inds_orbits):
for point_ind in orbit:
key_points_labels[point_ind] = self.LabelSymbol(int(orbit_labels[idx]))
key_points_labels[point_ind] = self.label_symbol(int(orbit_labels[idx]))

kpoints = {}
reverse_kpoints = {}
Expand Down Expand Up @@ -2030,7 +2030,7 @@ def _get_reciprocal_point_group_dict(recip_point_group, atol):
"inversion": [],
}

for i, op in enumerate(recip_point_group):
for idx, op in enumerate(recip_point_group):
evals, evects = np.linalg.eig(op)

tr = np.trace(op)
Expand All @@ -2044,50 +2044,50 @@ def _get_reciprocal_point_group_dict(recip_point_group, atol):
for j in range(3):
if np.isclose(evals[j], 1, atol=atol):
ax = evects[:, j]
dct["rotations"]["two-fold"].append({"ind": i, "axis": ax, "op": op})
dct["rotations"]["two-fold"].append({"ind": idx, "axis": ax, "op": op})
elif np.isclose(tr, 0, atol=atol): # three-fold rotation
for j in range(3):
if np.isreal(evals[j]) and np.isclose(np.absolute(evals[j]), 1, atol=atol):
ax = evects[:, j]
dct["rotations"]["three-fold"].append({"ind": i, "axis": ax, "op": op})
dct["rotations"]["three-fold"].append({"ind": idx, "axis": ax, "op": op})
# four-fold rotation
elif np.isclose(tr, 1, atol=atol):
for j in range(3):
if np.isreal(evals[j]) and np.isclose(np.absolute(evals[j]), 1, atol=atol):
ax = evects[:, j]
dct["rotations"]["four-fold"].append({"ind": i, "axis": ax, "op": op})
dct["rotations"]["four-fold"].append({"ind": idx, "axis": ax, "op": op})
elif np.isclose(tr, 2, atol=atol): # six-fold rotation
for j in range(3):
if np.isreal(evals[j]) and np.isclose(np.absolute(evals[j]), 1, atol=atol):
ax = evects[:, j]
dct["rotations"]["six-fold"].append({"ind": i, "axis": ax, "op": op})
dct["rotations"]["six-fold"].append({"ind": idx, "axis": ax, "op": op})

# Improper rotations
if np.isclose(det, -1, atol=atol):
if np.isclose(tr, -3, atol=atol):
dct["inversion"].append({"ind": i, "op": PAR})
dct["inversion"].append({"ind": idx, "op": PAR})
elif np.isclose(tr, 1, atol=atol): # two-fold rotation
for j in range(3):
if np.isclose(evals[j], -1, atol=atol):
norm = evects[:, j]
dct["reflections"].append({"ind": i, "normal": norm, "op": op})
dct["reflections"].append({"ind": idx, "normal": norm, "op": op})
elif np.isclose(tr, 0, atol=atol): # three-fold rotoinversion
for j in range(3):
if np.isreal(evals[j]) and np.isclose(np.absolute(evals[j]), 1, atol=atol):
ax = evects[:, j]
dct["rotations"]["rotoinv-three-fold"].append({"ind": i, "axis": ax, "op": op})
dct["rotations"]["rotoinv-three-fold"].append({"ind": idx, "axis": ax, "op": op})
# four-fold rotoinversion
elif np.isclose(tr, -1, atol=atol):
for j in range(3):
if np.isreal(evals[j]) and np.isclose(np.absolute(evals[j]), 1, atol=atol):
ax = evects[:, j]
dct["rotations"]["rotoinv-four-fold"].append({"ind": i, "axis": ax, "op": op})
dct["rotations"]["rotoinv-four-fold"].append({"ind": idx, "axis": ax, "op": op})
# six-fold rotoinversion
elif np.isclose(tr, -2, atol=atol):
for j in range(3):
if np.isreal(evals[j]) and np.isclose(np.absolute(evals[j]), 1, atol=atol):
ax = evects[:, j]
dct["rotations"]["rotoinv-six-fold"].append({"ind": i, "axis": ax, "op": op})
dct["rotations"]["rotoinv-six-fold"].append({"ind": idx, "axis": ax, "op": op})

return dct

Expand Down Expand Up @@ -2227,7 +2227,7 @@ def _get_max_cosine_labels(self, max_cosine_orbits_orig, key_points_inds_orbits,
return max_cosine_label_inds

@staticmethod
def LabelPoints(index):
def label_points(index):
"""Axes used in generating labels for Latimer-Munro convention."""
points = [
[1, 0, 0],
Expand Down Expand Up @@ -2261,35 +2261,7 @@ def LabelPoints(index):
return points[index]

@staticmethod
def LabelSymbol(index):
def label_symbol(index):
"""Letters used in generating labels for the Latimer-Munro convention."""
symbols = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
"Γ",
]
symbols = "a b c d e f g h i j k l m n o p q r s t u v w x y z Γ".split()
return symbols[index]
6 changes: 3 additions & 3 deletions pymatgen/vis/structure_vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

try:
import vtk
from vtk import vtkInteractorStyleTrackballCamera
from vtk import vtkInteractorStyleTrackballCamera as TrackballCamera
except ImportError:
# VTK not present. The Camera is to set object to avoid errors in unittest.
vtk = None
vtkInteractorStyleTrackballCamera = object
TrackballCamera = object

module_dir = os.path.dirname(os.path.abspath(__file__))
EL_COLORS = loadfn(f"{module_dir}/ElementColorSchemes.yaml")
Expand Down Expand Up @@ -772,7 +772,7 @@ def annotate_pick(obj, event):
self.iren.SetPicker(picker)


class StructureInteractorStyle(vtkInteractorStyleTrackballCamera):
class StructureInteractorStyle(TrackballCamera):
"""A custom interactor style for visualizing structures."""

def __init__(self, parent):
Expand Down
16 changes: 8 additions & 8 deletions tests/io/cp2k/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
coords=[[0, 0, 0], [0.25, 0.25, 0.25]],
)

nonsense_Structure = Structure(
nonsense_struct = Structure(
lattice=[[-1.0, -10.0, -100.0], [0.1, 0.01, 0.001], [7.0, 11.0, 21.0]],
species=["H"],
coords=[[-1, -1, -1]],
Expand All @@ -48,12 +48,12 @@
0.066918004004 0.037148121400
0.021708243634 -0.001125195500
"""
all_H = """
all_hydrogen = """
H ALLELECTRON ALL
1 0 0
0.20000000 0
"""
pot_H = """
pot_hydrogen = """
H GTH-PBE-q1 GTH-PBE
1
0.20000000 2 -4.17890044 0.72446331
Expand Down Expand Up @@ -125,16 +125,16 @@ def test_basis(self):

def test_potentials(self):
# Ensure cp2k formatted string can be read for data correctly
h_all_elec = GthPotential.from_str(all_H)
h_all_elec = GthPotential.from_str(all_hydrogen)
assert h_all_elec.potential == "All Electron"
pot = GthPotential.from_str(pot_H)
pot = GthPotential.from_str(pot_hydrogen)
assert pot.potential == "Pseudopotential"
assert pot.r_loc == approx(0.2)
assert pot.nexp_ppl == approx(2)
assert_allclose(pot.c_exp_ppl, [-4.17890044, 0.72446331])

# Basis file can read from strings
pf = PotentialFile.from_str(pot_H)
pf = PotentialFile.from_str(pot_hydrogen)
assert pf.objects[0] == pot

# Ensure keyword can be properly generated
Expand Down Expand Up @@ -181,13 +181,13 @@ def test_basic_keywords(self):
assert "[Ha]" in kwd.get_str()

def test_coords(self):
for strucs in [nonsense_Structure, Si_structure, molecule]:
for strucs in [nonsense_struct, Si_structure, molecule]:
coords = Coord(strucs)
for c in coords.keywords.values():
assert isinstance(c, (Keyword, KeywordList))

def test_kind(self):
for s in [nonsense_Structure, Si_structure, molecule]:
for s in [nonsense_struct, Si_structure, molecule]:
for spec in s.species:
assert spec == Kind(spec).specie

Expand Down
4 changes: 2 additions & 2 deletions tests/io/qchem/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
from monty.io import zopen

from pymatgen.io.qchem.utils import lower_and_check_unique, process_parsed_HESS
from pymatgen.io.qchem.utils import lower_and_check_unique, process_parsed_hess
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest

__author__ = "Ryan Kingsbury, Samuel Blau"
Expand Down Expand Up @@ -42,7 +42,7 @@ def test_process_parsed_hess(self):
with zopen(f"{test_dir}/parse_hess/HESS", mode="rt", encoding="ISO-8859-1") as f:
data_HESS = f.readlines()

processed_data_HESS = process_parsed_HESS(data_HESS)
processed_data_HESS = process_parsed_hess(data_HESS)

assert len(data_132) == len(processed_data_HESS)
for ii, val in enumerate(data_132):
Expand Down

0 comments on commit 2a43d25

Please sign in to comment.