Skip to content

Commit

Permalink
doc str + var name fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Nov 8, 2023
1 parent 535f925 commit 1c18213
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 74 deletions.
25 changes: 12 additions & 13 deletions dev_scripts/update_pt_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@
from monty.serialization import dumpfn, loadfn
from ruamel import yaml

from pymatgen.core import Element
from pymatgen.core.periodic_table import get_el_sp
from pymatgen.core import Element, get_el_sp


def test_yaml():
with open("periodic_table.yaml") as f:
data = yaml.load(f)
with open("periodic_table.yaml") as file:
data = yaml.load(file)
print(data)


def test_json():
with open("periodic_table.json") as f:
data = json.load(f)
with open("periodic_table.json") as file:
data = json.load(file)
print(data)


def parse_oxi_state():
with open("periodic_table.yaml") as f:
data = yaml.load(f)
with open("oxidation_states.txt") as f:
oxi_data = f.read()
with open("periodic_table.yaml") as file:
data = yaml.load(file)
with open("oxidation_states.txt") as file:
oxi_data = file.read()
oxi_data = re.sub("[\n\r]", "", oxi_data)
patt = re.compile("<tr>(.*?)</tr>", re.MULTILINE)

Expand Down Expand Up @@ -65,8 +64,8 @@ def parse_oxi_state():
data[el]["Common oxidation states"] = common_oxi
else:
print(el)
with open("periodic_table2.yaml", "w") as f:
yaml.dump(data, f)
with open("periodic_table2.yaml", "w") as file:
yaml.dump(data, file)


def parse_ionic_radii():
Expand Down Expand Up @@ -254,7 +253,7 @@ def add_electron_affinities():
import requests
from bs4 import BeautifulSoup

req = requests.get("https://en.wikipedia.org/wiki/Electron_affinity_(data_page)")
req = requests.get("https://wikipedia.org/wiki/Electron_affinity_(data_page)")
soup = BeautifulSoup(req.text, "html.parser")
for t in soup.find_all("table"):
if "Hydrogen" in t.text:
Expand Down
15 changes: 6 additions & 9 deletions pymatgen/alchemy/transmuters.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,15 @@ def append_transformation(self, transformation, extend_collection=False, clear_r
transformation: Transformation to append
extend_collection: Whether to use more than one output structure
from one-to-many transformations. extend_collection can be a
number, which determines the maximum branching for each
transformation.
number, which determines the maximum branching for each transformation.
clear_redo (bool): Whether to clear the redo list. By default,
this is True, meaning any appends clears the history of
undoing. However, when using append_transformation to do a
redo, the redo list should not be cleared to allow multiple
redos.
redo, the redo list should not be cleared to allow multiple redos.
Returns:
List of booleans corresponding to initial transformed structures
each boolean describes whether the transformation altered the
structure
list[bool]: corresponding to initial transformed structures each boolean
describes whether the transformation altered the structure
"""
if self.ncores and transformation.use_multiprocessing:
with Pool(self.ncores) as p:
Expand Down Expand Up @@ -369,8 +366,8 @@ def _apply_transformation(inputs):
collection, and a boolean indicating whether to clear the redo
Returns:
List of output structures (the modified initial structure, plus
any new structures created by a one-to-many transformation)
list[Structure]: the modified initial structure, plus
any new structures created by a one-to-many transformation
"""
ts, transformation, extend_collection, clear_redo = inputs
new = ts.append_transformation(transformation, extend_collection, clear_redo=clear_redo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
sort_separation,
sort_separation_tuple,
)
from pymatgen.core.lattice import Lattice
from pymatgen.core.periodic_table import Species
from pymatgen.core.structure import Structure
from pymatgen.core import Lattice, Species, Structure
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from pymatgen.util.due import Doi, due

Expand Down
12 changes: 6 additions & 6 deletions pymatgen/analysis/chemenv/utils/coordination_geometry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,11 @@ def rotateCoords(coords, R):
Returns:
List of rotated points.
"""
newlist = []
new_coords = []
for pp in coords:
rpp = matrixTimesVector(R, pp)
newlist.append(rpp)
return newlist
new_coords.append(rpp)
return new_coords


def rotateCoordsOpt(coords, R):
Expand Down Expand Up @@ -461,10 +461,10 @@ def changebasis(uu, vv, nn, pps):
MM[ii, 1] = vv[ii]
MM[ii, 2] = nn[ii]
PP = np.linalg.inv(MM)
newpps = []
new_pps = []
for pp in pps:
newpps.append(matrixTimesVector(PP, pp))
return newpps
new_pps.append(matrixTimesVector(PP, pp))
return new_pps


def collinear(p1, p2, p3=None, tolerance=0.25):
Expand Down
6 changes: 3 additions & 3 deletions pymatgen/analysis/chemenv/utils/math_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def divisors(n):
"""
factors = _factor_generator(n)
_divisors = []
listexponents = [[k**x for x in range(factors[k] + 1)] for k in list(factors)]
listfactors = _cartesian_product(listexponents)
for f in listfactors:
exponents = [[k**x for x in range(factors[k] + 1)] for k in list(factors)]
factors = _cartesian_product(exponents)
for f in factors:
_divisors.append(reduce(lambda x, y: x * y, f, 1))
_divisors.sort()
return _divisors
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/chempot_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def simple_pca(data: np.ndarray, k: int = 2) -> tuple[np.ndarray, np.ndarray, np
k: Number of principal components returned
Returns:
Tuple of projected data, eigenvalues, eigenvectors
tuple: projected data, eigenvalues, eigenvectors
"""
data = data - np.mean(data.T, axis=1) # centering the data
cov = np.cov(data.T) # calculating covariance matrix
Expand Down
26 changes: 13 additions & 13 deletions pymatgen/analysis/costdb_elements.csv
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
Ag,780.88,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "September", year = "2013", url = "http://www.wolframalpha.org"}|
Pd,23036.01,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "September", year = "2013", url = "http://www.wolframalpha.org"}|
C,24,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://en.wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Cl,1.5,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://en.wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
F,1900,pure F,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://en.wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Ir,42000,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://en.wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
K,1000,pure K,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://en.wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Na,250,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://en.wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
O,3,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://en.wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
P,300,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://en.wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Pa,280000,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://en.wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Sc,14000,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://en.wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Xe,1200,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://en.wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
C,24,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Cl,1.5,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
F,1900,pure F,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Ir,42000,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
K,1000,pure K,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Na,250,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
O,3,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
P,300,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Pa,280000,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Sc,14000,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Xe,1200,,|@misc{wikipedia, title = "Wikipedia", month = "September", year = "2013", url = "http://wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Al,2.46035592,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "September", year = "2013", url = "http://www.wolframalpha.org"}|
As,0.641103496,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "September", year = "2013", url = "http://www.wolframalpha.org"}|
Au,45386.51194,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "September", year = "2013", url = "http://www.wolframalpha.org"}|
B,0.871045362,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "September", year = "2013", url = "http://www.wolframalpha.org"}|
Ba,0.2605,,|@misc{wikipedia, title = "Wikipedia", month = "August", year = "2019", url = "http://en.wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Ba,0.2605,,|@misc{wikipedia, title = "Wikipedia", month = "August", year = "2019", url = "http://wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Be,447.978784,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "September", year = "2013", url = "http://www.wolframalpha.org"}|
Bi,25.3090376,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "September", year = "2013", url = "http://www.wolframalpha.org"}|
Br,1.39001291,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "September", year = "2013", url = "http://www.wolframalpha.org"}|
Expand Down Expand Up @@ -77,7 +77,7 @@ Yb,1599.892734,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "Septembe
Zn,2.33910182,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "September", year = "2013", url = "http://www.wolframalpha.org"}|
Zr,2.64995324,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "September", year = "2013", url = "http://www.wolframalpha.org"}|
He,15.9,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "June", year = "2020", url = "http://www.wolframalpha.org"}|
H,1.4,,|@misc{wikipedia, title = "Wikipedia", month = "June", year = "2020", url = "https://en.wikipedia.org/wiki/Hydrogen_economy#Costs"}|
H,1.4,,|@misc{wikipedia, title = "Wikipedia", month = "June", year = "2020", url = "https://wikipedia.org/wiki/Hydrogen_economy#Costs"}|
Ar,19.56,,|@misc{internet_search, title = "Aqua-Calc", month = "June", year = "2020", url = "https://www.aqua-calc.com/calculate/materials-price/substance/argon"}|
Ne,660000,,|@misc{internet_search, title = "Pomona College", month = "June", year = "2020", url = "http://www.chemistry.pomona.edu/chemistry/periodic_table/elements/neptunium/the%20facts.htm"}|
Kr,330,,|@misc{internet_search, title = "Chemicool", month = "June", year = "2020", url = "https://www.chemicool.com/elements/krypton.html"}|
Expand Down
3 changes: 1 addition & 2 deletions pymatgen/analysis/dimensionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
from pymatgen.analysis.graphs import MoleculeGraph, StructureGraph
from pymatgen.analysis.local_env import JmolNN
from pymatgen.analysis.structure_analyzer import get_max_bond_lengths
from pymatgen.core import Molecule, Species, Structure
from pymatgen.core.lattice import get_integer_index
from pymatgen.core.periodic_table import Species
from pymatgen.core.structure import Molecule, Structure
from pymatgen.core.surface import SlabGenerator
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer

Expand Down
6 changes: 2 additions & 4 deletions pymatgen/analysis/local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
from pymatgen.analysis.bond_valence import BV_PARAMS, BVAnalyzer
from pymatgen.analysis.graphs import MoleculeGraph, StructureGraph
from pymatgen.analysis.molecule_structure_comparator import CovalentRadius
from pymatgen.core.periodic_table import Element, Species
from pymatgen.core.sites import PeriodicSite, Site
from pymatgen.core.structure import IStructure, PeriodicNeighbor, Structure
from pymatgen.core import Element, IStructure, PeriodicNeighbor, PeriodicSite, Site, Species, Structure

try:
from openbabel import openbabel
Expand Down Expand Up @@ -1929,7 +1927,7 @@ def solid_angle(center, coords):
r_norm = [np.linalg.norm(i) for i in r]

# Compute the solid angle for each tetrahedron that makes up the facet
# Following: https://en.wikipedia.org/wiki/Solid_angle#Tetrahedron
# Following: https://wikipedia.org/wiki/Solid_angle#Tetrahedron
angle = 0
for i in range(1, len(r) - 1):
j = i + 1
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/molecule_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ def kabsch(P: np.ndarray, Q: np.ndarray):
P and Q, centered around the their centroid.
For more info see:
- http://en.wikipedia.org/wiki/Kabsch_algorithm and
- http://wikipedia.org/wiki/Kabsch_algorithm and
- https://cnx.org/contents/HV-RsdwL@23/Molecular-Distance-Measures
Args:
Expand Down
5 changes: 2 additions & 3 deletions pymatgen/analysis/phase_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -2028,8 +2028,7 @@ class PhaseDiagramError(Exception):


def get_facets(qhull_data: ArrayLike, joggle: bool = False) -> ConvexHull:
"""
Get the simplex facets for the Convex hull.
"""Get the simplex facets for the Convex hull.
Args:
qhull_data (np.ndarray): The data from which to construct the convex
Expand All @@ -2039,7 +2038,7 @@ def get_facets(qhull_data: ArrayLike, joggle: bool = False) -> ConvexHull:
errors.
Returns:
List of simplices of the Convex Hull.
scipy.spatial.ConvexHull: with list of simplices of the convex hull.
"""
if joggle:
return ConvexHull(qhull_data, qhull_options="QJ i").simplices
Expand Down
3 changes: 1 addition & 2 deletions pymatgen/analysis/pourbaix_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@

from pymatgen.analysis.phase_diagram import PDEntry, PhaseDiagram
from pymatgen.analysis.reaction_calculator import Reaction, ReactionError
from pymatgen.core.composition import Composition
from pymatgen.core import Composition, Element
from pymatgen.core.ion import Ion
from pymatgen.core.periodic_table import Element
from pymatgen.entries.compatibility import MU_H2O
from pymatgen.entries.computed_entries import ComputedEntry
from pymatgen.util.coord import Simplex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from monty.design_patterns import cached_class

from pymatgen.core.periodic_table import Species, get_el_sp
from pymatgen.core import Species, get_el_sp
from pymatgen.util.due import Doi, due

__author__ = "Will Richards, Geoffroy Hautier"
Expand Down
3 changes: 1 addition & 2 deletions pymatgen/apps/battery/insertion_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

from pymatgen.analysis.phase_diagram import PDEntry, PhaseDiagram
from pymatgen.apps.battery.battery_abc import AbstractElectrode, AbstractVoltagePair
from pymatgen.core.composition import Composition
from pymatgen.core.periodic_table import Element
from pymatgen.core import Composition, Element
from pymatgen.core.units import Charge, Time
from pymatgen.entries.computed_entries import ComputedEntry, ComputedStructureEntry

Expand Down
13 changes: 10 additions & 3 deletions pymatgen/command_line/mcsqs_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def run_mcsqs(
tol (int or float): Tolerance for matching correlations (default: 1e-3).
Returns:
Tuple of Pymatgen structure SQS of the input structure, the mcsqs objective function,
tuple: Pymatgen structure SQS of the input structure, the mcsqs objective function,
list of all SQS structures, and the directory where calculations are run
"""
num_atoms = len(structure)
Expand Down Expand Up @@ -166,7 +166,7 @@ def _parse_sqs_path(path) -> Sqs:
path: directory to perform parsing.
Returns:
Tuple of Pymatgen structure SQS of the input structure, the mcsqs objective function,
tuple: Pymatgen structure SQS of the input structure, the mcsqs objective function,
list of all SQS structures, and the directory where calculations are run
"""
path = Path(path)
Expand Down Expand Up @@ -225,7 +225,14 @@ def _parse_clusters(filename):
path: directory to perform parsing.
Returns:
List of dicts
list[dict]: List of cluster dictionaries with keys:
multiplicity: int
longest_pair_length: float
num_points_in_cluster: int
coordinates: list[dict] of points with keys:
coordinates: list[float]
num_possible_species: int
cluster_function: float
"""
with open(filename) as f:
lines = f.readlines()
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class SymmOp(MSONable):
"""A symmetry operation in Cartesian space. Consists of a rotation plus a
translation. Implementation is as an affine transformation matrix of rank 4
for efficiency. Read: http://en.wikipedia.org/wiki/Affine_transformation.
for efficiency. Read: http://wikipedia.org/wiki/Affine_transformation.
Attributes:
affine_matrix (np.ndarray): A 4x4 array representing the symmetry operation.
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, symbol: SpeciesLike):
symbol (str): Element symbol.
long_name (str): Long name for element. E.g., "Hydrogen".
atomic_radius_calculated (float): Calculated atomic radius for the element. This is the empirical value.
Data is obtained from http://en.wikipedia.org/wiki/Atomic_radii_of_the_elements_(data_page).
Data is obtained from http://wikipedia.org/wiki/Atomic_radii_of_the_elements_(data_page).
van_der_waals_radius (float): Van der Waals radius for the element. This is the empirical value determined
from critical reviews of X-ray diffraction, gas kinetic collision cross-section, and other experimental
data by Bondi and later workers. The uncertainty in these values is on the order of 0.1 Å.
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/util/coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def get_angle(v1: ArrayLike, v2: ArrayLike, units: Literal["degrees", "radians"]


class Simplex(MSONable):
"""A generalized simplex object. See http://en.wikipedia.org/wiki/Simplex.
"""A generalized simplex object. See http://wikipedia.org/wiki/Simplex.
Attributes:
space_dim (int): Dimension of the space. Usually, this is 1 more than the simplex_dim.
Expand Down Expand Up @@ -409,7 +409,7 @@ def in_simplex(self, point, tolerance=1e-8):
simplex from this origin by subtracting all other vertices from the
origin. We then project the point into this coordinate system and
determine the linear decomposition coefficients in this coordinate
system. If the coeffs satisfy that all coeffs >= 0, the composition
system. If the coeffs satisfy all(coeffs >= 0), the composition
is in the facet.
Args:
Expand Down
4 changes: 2 additions & 2 deletions tests/files/costdb_1.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
O,1,,|@misc{wikipedia, title = "Wikipedia", month = "August", year = "2013", url = "http://en.wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Ag,3,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "September", year = "2013", url = "http://www.wolframalpha.org"}|
O,1,,|@misc{wikipedia, title = "Wikipedia", month = "August", year = "2013", url = "http://wikipedia.org/wiki/Prices_of_elements_and_their_compounds"}|
Ag,3,,|@misc{wolfram_alpha, title = "Wolfram Alpha", month = "September", year = "2013", url = "http://www.wolframalpha.org"}|
Loading

0 comments on commit 1c18213

Please sign in to comment.