Skip to content

Commit

Permalink
Fix CI (#2767)
Browse files Browse the repository at this point in the history
* fix typos

* fix AttributeError: 'range' object has no attribute 'remove' in dev_scripts/chemenv/equivalent_indices.py

* add missing doc strings in dev_scripts/chemenv/strategies/multi_weights_strategy_parameters.py

* fix TypeError: Object of type ndarray is not JSON serializable

in         with open("tmp_dir/lse.json", "w") as f:
>           json.dump(lse.as_dict(), f)

pymatgen/analysis/chemenv/coordination_environments/tests/test_read_write.py:81:
  • Loading branch information
janosh authored Dec 5, 2022
1 parent caeeb3e commit e612cc5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dev_scripts/chemenv/equivalent_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
for i2 in perp_plane[i0]:
# 3. point opposite to point 2.
i3 = opposite_points[i2]
remaining = range(6)
remaining = list(range(6))
remaining.remove(i0)
remaining.remove(i1)
remaining.remove(i2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import copy
import json
from typing import Sequence

import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -41,6 +42,10 @@


class CoordinationEnvironmentMorphing:
"""
Class to morph a coordination environment into another one.
"""

def __init__(self, initial_environment_symbol, expected_final_environment_symbol, morphing_description):
self.initial_environment_symbol = initial_environment_symbol
self.expected_final_environment_symbol = expected_final_environment_symbol
Expand All @@ -50,6 +55,17 @@ def __init__(self, initial_environment_symbol, expected_final_environment_symbol

@classmethod
def simple_expansion(cls, initial_environment_symbol, expected_final_environment_symbol, neighbors_indices):
"""
Simple expansion of a coordination environment.
Args:
initial_environment_symbol (str): The initial coordination environment symbol.
expected_final_environment_symbol (str): The expected final coordination environment symbol.
neighbors_indices (list): The indices of the neighbors to be expanded.
Returns:
CoordinationEnvironmentMorphing
"""
morphing_description = [
{"ineighbor": i_nb, "site_type": "neighbor", "expansion_origin": "central_site"}
for i_nb in neighbors_indices
Expand All @@ -60,7 +76,14 @@ def simple_expansion(cls, initial_environment_symbol, expected_final_environment
morphing_description=morphing_description,
)

def figure_fractions(self, weights_options, morphing_factors=None):
def figure_fractions(self, weights_options: dict, morphing_factors: Sequence[float] = None) -> None:
"""
Plot the fractions of the initial and final coordination environments as a function of the morphing factor.
Args:
weights_options (dict): The weights options.
morphing_factors (list): The morphing factors.
"""
if morphing_factors is None:
morphing_factors = np.linspace(1.0, 2.0, 21)
# Set up the local geometry finder
Expand All @@ -69,7 +92,7 @@ def figure_fractions(self, weights_options, morphing_factors=None):
# Set up the weights for the MultiWeights strategy
weights = self.get_weights(weights_options)
# Set up the strategy
strat = MultiWeightsChemenvStrategy(
strategy = MultiWeightsChemenvStrategy(
dist_ang_area_weight=weights["DistAngArea"],
self_csm_weight=weights["SelfCSM"],
delta_csm_weight=weights["DeltaCSM"],
Expand All @@ -88,8 +111,8 @@ def figure_fractions(self, weights_options, morphing_factors=None):
# Get the StructureEnvironments
lgf.setup_structure(structure=struct)
se = lgf.compute_structure_environments(only_indices=[0], valences=fake_valences)
strat.set_structure_environments(structure_environments=se)
result = strat.get_site_coordination_environments_fractions(
strategy.set_structure_environments(structure_environments=se)
result = strategy.get_site_coordination_environments_fractions(
site=se.structure[0], isite=0, return_strategy_dict_info=True, return_all=True
)
for res in result:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ def test_read_write_structure_environments(self):
)

with open("tmp_dir/lse.json", "w") as f:
json.dump(lse.as_dict(), f)
json.dump(lse.as_dict(), f, default=lambda o: o.tolist() if hasattr(o, "tolist") else o)

with open("tmp_dir/lse.json") as f:
dd = json.load(f)

lse2 = LightStructureEnvironments.from_dict(dd)
lse2 = LightStructureEnvironments.from_dict(json.load(f))

assert lse == lse2

Expand Down
6 changes: 3 additions & 3 deletions pymatgen/analysis/tests/test_functional_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def setUp(self):

self.file = os.path.join(test_dir, "func_group_test.mol")
self.mol = Molecule.from_file(self.file)
self.strat = OpenBabelNN()
self.mg = MoleculeGraph.with_local_env_strategy(self.mol, self.strat)
self.strategy = OpenBabelNN()
self.mg = MoleculeGraph.with_local_env_strategy(self.mol, self.strategy)
self.extractor = FunctionalGroupExtractor(self.mg)

def tearDown(self):
warnings.simplefilter("default")
del self.extractor
del self.mg
del self.strat
del self.strategy
del self.mol
del self.file

Expand Down
4 changes: 2 additions & 2 deletions pymatgen/io/qchem/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,8 +982,8 @@ def read_pcm_nonels(string: str) -> dict:
pcm_nonels_table = read_table_pattern(string, header_pattern=header, row_pattern=row, footer_pattern=footer)
if not pcm_nonels_table:
print(
"No valid $pcm_nonels inputs found. Note that there should be no '=' \
chracters in $pcm_nonels input lines."
"No valid $pcm_nonels inputs found. Note that there should be no '=' "
"characters in $pcm_nonels input lines."
)
return {}

Expand Down
14 changes: 7 additions & 7 deletions pymatgen/io/qchem/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def __init__(
Other types of PCM calculations (e.g., IEF-PCM, SS(V)PE, etc.) may be requested by passing
custom keywords to overwrite_inputs, e.g.
overwrite_inputs = {"pcm": {"theory": "ssvpe"}}
Refer to the QChem manual for further details on the models availale.
Refer to the QChem manual for further details on the models available.
**Note that only one of pcm_dielectric, isosvp_dielectric, smd_solvent, or cmirs_solvent may be set.**
isosvp_dielectric (float): Dielectric constant to use for isodensity SS(V)PE implicit solvation model.
Expand Down Expand Up @@ -583,7 +583,7 @@ def __init__(
Other types of PCM calculations (e.g., IEF-PCM, SS(V)PE, etc.) may be requested by passing
custom keywords to overwrite_inputs, e.g.
overwrite_inputs = {"pcm": {"theory": "ssvpe"}}
Refer to the QChem manual for further details on the models availale.
Refer to the QChem manual for further details on the models available.
**Note that only one of pcm_dielectric, isosvp_dielectric, smd_solvent, or cmirs_solvent may be set.**
isosvp_dielectric (float): Dielectric constant to use for isodensity SS(V)PE implicit solvation model.
Expand Down Expand Up @@ -712,7 +712,7 @@ def __init__(
Other types of PCM calculations (e.g., IEF-PCM, SS(V)PE, etc.) may be requested by passing
custom keywords to overwrite_inputs, e.g.
overwrite_inputs = {"pcm": {"theory": "ssvpe"}}
Refer to the QChem manual for further details on the models availale.
Refer to the QChem manual for further details on the models available.
**Note that only one of pcm_dielectric, isosvp_dielectric, smd_solvent, or cmirs_solvent may be set.**
isosvp_dielectric (float): Dielectric constant to use for isodensity SS(V)PE implicit solvation model.
Expand Down Expand Up @@ -834,7 +834,7 @@ def __init__(
Other types of PCM calculations (e.g., IEF-PCM, SS(V)PE, etc.) may be requested by passing
custom keywords to overwrite_inputs, e.g.
overwrite_inputs = {"pcm": {"theory": "ssvpe"}}
Refer to the QChem manual for further details on the models availale.
Refer to the QChem manual for further details on the models available.
**Note that only one of pcm_dielectric, isosvp_dielectric, smd_solvent, or cmirs_solvent may be set.**
isosvp_dielectric (float): Dielectric constant to use for isodensity SS(V)PE implicit solvation model.
Expand Down Expand Up @@ -953,7 +953,7 @@ def __init__(
Other types of PCM calculations (e.g., IEF-PCM, SS(V)PE, etc.) may be requested by passing
custom keywords to overwrite_inputs, e.g.
overwrite_inputs = {"pcm": {"theory": "ssvpe"}}
Refer to the QChem manual for further details on the models availale.
Refer to the QChem manual for further details on the models available.
**Note that only one of pcm_dielectric, isosvp_dielectric, smd_solvent, or cmirs_solvent may be set.**
isosvp_dielectric (float): Dielectric constant to use for isodensity SS(V)PE implicit solvation model.
Expand Down Expand Up @@ -1069,7 +1069,7 @@ def __init__(
Other types of PCM calculations (e.g., IEF-PCM, SS(V)PE, etc.) may be requested by passing
custom keywords to overwrite_inputs, e.g.
overwrite_inputs = {"pcm": {"theory": "ssvpe"}}
Refer to the QChem manual for further details on the models availale.
Refer to the QChem manual for further details on the models available.
**Note that only one of pcm_dielectric, isosvp_dielectric, smd_solvent, or cmirs_solvent may be set.**
isosvp_dielectric (float): Dielectric constant to use for isodensity SS(V)PE implicit solvation model.
Expand Down Expand Up @@ -1205,7 +1205,7 @@ def __init__(
Other types of PCM calculations (e.g., IEF-PCM, SS(V)PE, etc.) may be requested by passing
custom keywords to overwrite_inputs, e.g.
overwrite_inputs = {"pcm": {"theory": "ssvpe"}}
Refer to the QChem manual for further details on the models availale.
Refer to the QChem manual for further details on the models available.
**Note that only one of pcm_dielectric, isosvp_dielectric, smd_solvent, or cmirs_solvent may be set.**
isosvp_dielectric (float): Dielectric constant to use for isodensity SS(V)PE implicit solvation model.
Expand Down

0 comments on commit e612cc5

Please sign in to comment.