Skip to content

Commit

Permalink
Breaking: rename get_ax3d_fig_plt->get_ax3d_fig and `get_ax_fig_plt…
Browse files Browse the repository at this point in the history
…->get_ax_fig` plus no longer return `plt` (#3329)

* breaking: rename get_ax3d_fig_plt->get_ax3d_fig and stop returning matplotlib.pyplot

* breaking: same for get_ax_fig_plt->get_ax_fig

* remove :class:`SomeObject` from doc strings

probably doesn't work with new markdown docs, can't check without network atm

* simplify doc strings: pymatgen.core.(lattice.->'')Lattice

* blank line before all Args: and Returns: doc string section headers

* use dict.setdefault() instead of checking key presence first

* doc string indentation and line break fixes

* fix doc string Returns: sections

* define reusable LatticeType and CrystalSystem types

* simplify with_local_env_strategy() sg.add_edge() call
  • Loading branch information
janosh authored Sep 16, 2023
1 parent b4e6208 commit be6b695
Show file tree
Hide file tree
Showing 83 changed files with 859 additions and 711 deletions.
21 changes: 13 additions & 8 deletions pymatgen/alchemy/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def __init__(self, species, strict_compare=False, AND=True, exclude=False):
def test(self, structure: Structure):
"""Method to execute the test.
Returns: True if structure do not contain specified species.
Returns:
bool: True if structure does not contain specified species.
"""
# set up lists to compare
if not self._strict:
Expand Down Expand Up @@ -139,8 +140,8 @@ def test(self, structure: Structure):
Args:
structure (Structure): Input structure to test
Returns: True if structure does not contain species within specified
distances.
Returns:
bool: True if structure does not contain species within specified distances.
"""
all_species = set(self.specie_and_min_dist)
for site in structure:
Expand Down Expand Up @@ -203,7 +204,8 @@ def test(self, structure: Structure):
Args:
structure (Structure): Input structure to test.
Returns: True if structure is not in list.
Returns:
bool: True if structure is not in list.
"""
hash = self.structure_matcher._comparator.get_hash(structure.composition)
if not self.structure_list[hash]:
Expand Down Expand Up @@ -253,7 +255,8 @@ def test(self, structure: Structure):
Args:
structure (Structure): Input structure to test
Returns: True if structure is not in existing list.
Returns:
bool: True if structure is not in existing list.
"""

def get_sg(s):
Expand Down Expand Up @@ -297,7 +300,8 @@ def test(self, structure: Structure):
Args:
structure (Structure): Input structure to test
Returns: True if structure is neutral.
Returns:
bool: True if structure is neutral.
"""
return structure.charge == 0.0

Expand Down Expand Up @@ -329,8 +333,9 @@ def test(self, structure: Structure):
Args:
structure (Structure): Input structure to test
Returns: True if structure does not contain the two species are distances
greater than max_dist.
Returns:
bool: True if structure does not contain the two species are distances
greater than max_dist.
"""
sp1_indices = [idx for idx, site in enumerate(structure) if site.specie == self.sp1]
sp2_indices = [idx for idx, site in enumerate(structure) if site.specie == self.sp2]
Expand Down
6 changes: 3 additions & 3 deletions pymatgen/alchemy/transmuters.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def __init__(
self,
transformed_structures,
transformations=None,
extend_collection=0,
ncores=None,
extend_collection: int = 0,
ncores: int | None = None,
):
"""Initializes a transmuter from an initial list of
:class:`pymatgen.alchemy.materials.TransformedStructure`.
pymatgen.alchemy.materials.TransformedStructure.
Args:
transformed_structures ([TransformedStructure]): Input transformed
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/bond_dissociation.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(
raise RuntimeError(key + " must be present in molecule entry! Exiting...")
for entry in self.filtered_entries:
if key not in entry:
raise RuntimeError(key + " must be present in all fragment entries! Exiting...")
raise RuntimeError(f"{key=} must be present in all fragment entries! Exiting...")

# Define expected charges
final_charge = int(molecule_entry["final_molecule"]["charge"]) # type: ignore[index]
Expand Down
27 changes: 12 additions & 15 deletions pymatgen/analysis/chemenv/connectivity/connected_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ def draw_network(env_graph, pos, ax, sg=None, periodicity_vectors=None):
ax: Axes object in which the network should be drawn.
sg: Not used currently (drawing of supergraphs).
periodicity_vectors: List of periodicity vectors that should be drawn.
Returns: None
"""
for n in env_graph:
c = Circle(pos[n], radius=0.02, alpha=0.5)
Expand Down Expand Up @@ -124,18 +121,18 @@ def draw_network(env_graph, pos, ax, sg=None, periodicity_vectors=None):


def make_supergraph(graph, multiplicity, periodicity_vectors):
"""Make supergraph from a graph of environments.
"""Make super graph from a graph of environments.
Args:
graph: Graph of environments.
multiplicity: Multiplicity of the supergraph.
periodicity_vectors: Periodicity vectors needed to make the supergraph.
Returns: Super graph of the environments.
multiplicity: Multiplicity of the super graph.
periodicity_vectors: Periodicity vectors needed to make the super graph.
Returns:
nx.MultiGraph: Super graph of the environments.
"""
supergraph = nx.MultiGraph()
print("peridoicity vectors :")
super_graph = nx.MultiGraph()
print("periodicity vectors :")
print(periodicity_vectors)
if isinstance(multiplicity, int) or len(multiplicity) == 1:
mult = multiplicity if isinstance(multiplicity, int) else multiplicity[0]
Expand Down Expand Up @@ -173,25 +170,25 @@ def make_supergraph(graph, multiplicity, periodicity_vectors):
new_data = dict(data)
new_data["start"] = (imult * len(nodes)) + indices_nodes[n1]
new_data["end"] = (imult * len(nodes)) + indices_nodes[n2]
supergraph.add_edge(new_data["start"], new_data["end"], key=key, attr_dict=new_data)
super_graph.add_edge(new_data["start"], new_data["end"], key=key, attr_dict=new_data)
for n1, n2, key, data in connecting_edges:
new_data = dict(data)
new_data["start"] = (imult * len(nodes)) + indices_nodes[n1]
new_data["end"] = np.mod(((imult + 1) * len(nodes)) + indices_nodes[n2], len(nodes) * mult)
new_data["delta"] = (0, 0, 0)
supergraph.add_edge(new_data["start"], new_data["end"], key=key, attr_dict=new_data)
super_graph.add_edge(new_data["start"], new_data["end"], key=key, attr_dict=new_data)
imult = mult - 1
for n1, n2, key, data in other_edges:
new_data = dict(data)
new_data["start"] = (imult * len(nodes)) + indices_nodes[n1]
new_data["end"] = (imult * len(nodes)) + indices_nodes[n2]
supergraph.add_edge(new_data["start"], new_data["end"], key=key, attr_dict=new_data)
super_graph.add_edge(new_data["start"], new_data["end"], key=key, attr_dict=new_data)
for n1, n2, key, data in connecting_edges:
new_data = dict(data)
new_data["start"] = (imult * len(nodes)) + indices_nodes[n1]
new_data["end"] = indices_nodes[n2]
supergraph.add_edge(new_data["start"], new_data["end"], key=key, attr_dict=new_data)
return supergraph
super_graph.add_edge(new_data["start"], new_data["end"], key=key, attr_dict=new_data)
return super_graph

raise NotImplementedError("make_supergraph not yet implemented for 2- and 3-periodic graphs")

Expand Down
Loading

0 comments on commit be6b695

Please sign in to comment.