Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faff #2915

Merged
merged 5 commits into from
Mar 28, 2023
Merged

Faff #2915

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed docs/_static/examples.png
Binary file not shown.
2 changes: 1 addition & 1 deletion docs_rst/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ One of the ways you can contribute is to fork the matgenb repo and add your own

Below are a quick look at some of the graphical output possible.

.. figure:: _static/examples.png
.. figure:: _static/phase_diagram.png
:width: 100%
:alt: Examples
:align: center
Expand Down
9 changes: 8 additions & 1 deletion docs_rst/team.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,18 @@ Lead Maintainers

| **Janosh Riebesell** |janosh|
| University of Cambridge
| Materials Project Staff
.. |janosh| image:: https://cdnjs.cloudflare.com/ajax/libs/octicons/8.5.0/svg/mark-github.svg
:target: https://github.com/materialsproject/pymatgen/pulls?q=is:pr+author:janosh
:width: 16
:height: 16
:alt: GitHub profile for janosh
:alt: janosh GitHub profile

.. |janosh.dev| image:: https://cdnjs.cloudflare.com/ajax/libs/octicons/8.5.0/svg/browser.svg
:target: https://janosh.dev
:width: 16
:height: 16
:alt: janosh homepage

Newest Contributors
===================
Expand Down
12 changes: 6 additions & 6 deletions docs_rst/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ which is a general python supplementary library arising from pymatgen.
The output from an as_dict method is always json/yaml serializable. So if you
want to save a structure, you may do the following::

with open('structure.json','w') as f:
json.dump(structure.as_dict(), f)
with open('structure.json', 'w') as file:
json.dump(structure.as_dict(), file)

Similarly, to get the structure back from a json, you can do the following to
restore the structure (or any object with a as_dict method) from the json as
restore the structure (or any object with an as_dict method) from the json as
follows::

with open('structure.json', 'r') as f:
d = json.load(f)
structure = Structure.from_dict(d)
with open('structure.json') as file:
dct = json.load(file)
structure = Structure.from_dict(dct)

You may replace any of the above json commands with yaml in the PyYAML package
to create a yaml file instead. There are certain tradeoffs between the two
Expand Down
36 changes: 18 additions & 18 deletions pymatgen/analysis/local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3856,25 +3856,25 @@ def get_nn_info(self, structure: Structure, n: int) -> list[dict]:
to the coordination number (1 or smaller), 'site_index' gives index of
the corresponding site in the original structure.
"""
nndata = self.get_nn_data(structure, n)
nn_data = self.get_nn_data(structure, n)

if not self.weighted_cn:
max_key = max(nndata.cn_weights, key=lambda k: nndata.cn_weights[k])
nn = nndata.cn_nninfo[max_key]
max_key = max(nn_data.cn_weights, key=lambda k: nn_data.cn_weights[k])
nn = nn_data.cn_nninfo[max_key]
for entry in nn:
entry["weight"] = 1
return nn

for entry in nndata.all_nninfo:
for entry in nn_data.all_nninfo:
weight = 0
for cn in nndata.cn_nninfo:
for cn_entry in nndata.cn_nninfo[cn]:
for cn in nn_data.cn_nninfo:
for cn_entry in nn_data.cn_nninfo[cn]:
if entry["site"] == cn_entry["site"]:
weight += nndata.cn_weights[cn]
weight += nn_data.cn_weights[cn]

entry["weight"] = weight

return nndata.all_nninfo
return nn_data.all_nninfo

def get_nn_data(self, structure: Structure, n: int, length=None):
"""
Expand All @@ -3887,9 +3887,9 @@ def get_nn_data(self, structure: Structure, n: int, length=None):

Returns:
a namedtuple (NNData) object that contains:
- all near neighbor sites with weights
- a dict of CN -> weight
- a dict of CN -> associated near neighbor sites
- all near neighbor sites with weights
- a dict of CN -> weight
- a dict of CN -> associated near neighbor sites
"""
length = length or self.fingerprint_length

Expand Down Expand Up @@ -4082,23 +4082,23 @@ def _semicircle_integral(dist_bins, idx):
return (area1 - area2) / (0.25 * math.pi * r**2)

@staticmethod
def transform_to_length(nndata, length):
def transform_to_length(nn_data, length):
"""
Given NNData, transforms data to the specified fingerprint length
Args:
nndata: (NNData)
nn_data: (NNData)
length: (int) desired length of NNData
"""
if length is None:
return nndata
return nn_data

if length:
for cn in range(length):
if cn not in nndata.cn_weights:
nndata.cn_weights[cn] = 0
nndata.cn_nninfo[cn] = []
if cn not in nn_data.cn_weights:
nn_data.cn_weights[cn] = 0
nn_data.cn_nninfo[cn] = []

return nndata
return nn_data


def _get_default_radius(site):
Expand Down
6 changes: 3 additions & 3 deletions pymatgen/analysis/tests/test_local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,9 +1317,9 @@ def test_weighted_cn_no_oxid(self):

def test_fixed_length(self):
cnn = CrystalNN(fingerprint_length=30)
nndata = cnn.get_nn_data(self.lifepo4, 0)
assert len(nndata.cn_weights) == 30
assert len(nndata.cn_nninfo) == 30
nn_data = cnn.get_nn_data(self.lifepo4, 0)
assert len(nn_data.cn_weights) == 30
assert len(nn_data.cn_nninfo) == 30

def test_cation_anion(self):
cnn = CrystalNN(weighted_cn=True, cation_anion=True)
Expand Down
30 changes: 15 additions & 15 deletions pymatgen/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@

from ruamel.yaml import YAML

from .composition import Composition as Composition
from .lattice import Lattice as Lattice
from .operations import SymmOp as SymmOp
from .periodic_table import DummySpecies as DummySpecies
from .periodic_table import Element as Element
from .periodic_table import Species as Species
from .sites import PeriodicSite as PeriodicSite
from .sites import Site as Site
from .structure import IMolecule as IMolecule
from .structure import IStructure as IStructure
from .structure import Molecule as Molecule
from .structure import Structure as Structure
from .units import ArrayWithUnit as ArrayWithUnit
from .units import FloatWithUnit as FloatWithUnit
from .units import Unit as Unit
from pymatgen.core.composition import Composition as Composition
from pymatgen.core.lattice import Lattice as Lattice
from pymatgen.core.operations import SymmOp as SymmOp
from pymatgen.core.periodic_table import DummySpecies as DummySpecies
from pymatgen.core.periodic_table import Element as Element
from pymatgen.core.periodic_table import Species as Species
from pymatgen.core.sites import PeriodicSite as PeriodicSite
from pymatgen.core.sites import Site as Site
from pymatgen.core.structure import IMolecule as IMolecule
from pymatgen.core.structure import IStructure as IStructure
from pymatgen.core.structure import Molecule as Molecule
from pymatgen.core.structure import Structure as Structure
from pymatgen.core.units import ArrayWithUnit as ArrayWithUnit
from pymatgen.core.units import FloatWithUnit as FloatWithUnit
from pymatgen.core.units import Unit as Unit

__author__ = "Pymatgen Development Team"
__email__ = "pymatgen@googlegroups.com"
Expand Down
13 changes: 1 addition & 12 deletions pymatgen/util/coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,7 @@ def lattice_points_in_supercell(supercell_matrix):
Returns:
numpy array of the fractional coordinates
"""
diagonals = np.array(
[
[0, 0, 0],
[0, 0, 1],
[0, 1, 0],
[0, 1, 1],
[1, 0, 0],
[1, 0, 1],
[1, 1, 0],
[1, 1, 1],
]
)
diagonals = np.array([[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]])
d_points = np.dot(diagonals, supercell_matrix)

mins = np.min(d_points, axis=0)
Expand Down
62 changes: 26 additions & 36 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,29 @@ def make_doc(ctx):

:param ctx:
"""
with open("CHANGES.rst") as f:
contents = f.read()
with open("CHANGES.rst") as file:
contents = file.read()

toks = re.split(r"\-{3,}", contents)
n = len(toks[0].split()[-1])
changes = [toks[0]]
changes.append("\n" + "\n".join(toks[1].strip().split("\n")[0:-1]))
changes = ("-" * n).join(changes)

with open("docs_rst/latest_changes.rst", "w") as f:
f.write(changes)
with open("docs_rst/latest_changes.rst", "w") as file:
file.write(changes)

with cd("docs_rst"):
ctx.run("cp ../CHANGES.rst change_log.rst")
ctx.run("rm pymatgen.*.rst", warn=True)
ctx.run("sphinx-apidoc --implicit-namespaces --separate -d 7 -o . -f ../pymatgen")
ctx.run("rm *.tests.*rst")
for f in glob("*.rst"):
if f.startswith("pymatgen") and f.endswith("rst"):
for file in glob("*.rst"):
if file.startswith("pymatgen") and file.endswith("rst"):
new_output = []
sub_output = []
sub_package = False
with open(f) as fid:
with open(file) as fid:
for line in fid:
clean = line.strip()
if clean == "Subpackages":
Expand All @@ -67,7 +67,7 @@ def make_doc(ctx):
sub_package = False
sub_output = []

with open(f, "w") as fid:
with open(file, "w") as fid:
fid.write("".join(new_output))
ctx.run("make html")

Expand Down Expand Up @@ -109,16 +109,6 @@ def make_dash(ctx):
with open(plist, "w") as file:
file.write("\n".join(xml))
ctx.run('tar --exclude=".DS_Store" -cvzf pymatgen.tgz pymatgen.docset')
# xml = []
# with open("docs/pymatgen.xml") as f:
# for l in f:
# l = l.strip()
# if l.startswith("<version>"):
# xml.append(f"<version>{version}</version>")
# else:
# xml.append(l)
# with open("docs/pymatgen.xml", "wt") as f:
# f.write("\n".join(xml))
ctx.run("rm -r pymatgen.docset")
ctx.run("cp docs_rst/conf-normal.py docs_rst/conf.py")

Expand All @@ -128,11 +118,11 @@ def contribute_dash(ctx, version):
make_dash(ctx)
ctx.run("cp pymatgen.tgz ../Dash-User-Contributions/docsets/pymatgen/pymatgen.tgz")
with cd("../Dash-User-Contributions/docsets/pymatgen"):
with open("docset.json") as f:
data = json.load(f)
with open("docset.json") as file:
data = json.load(file)
data["version"] = version
with open("docset.json", "w") as f:
json.dump(data, f, indent=4)
with open("docset.json", "w") as file:
json.dump(data, file, indent=4)
ctx.run(f'git commit --no-verify -a -m "Update to v{version}"')
ctx.run("git push")
ctx.run("rm pymatgen.tgz")
Expand Down Expand Up @@ -181,19 +171,19 @@ def publish(ctx):

@task
def set_ver(ctx, version):
with open("pymatgen/core/__init__.py") as f:
contents = f.read()
with open("pymatgen/core/__init__.py") as file:
contents = file.read()
contents = re.sub(r"__version__ = .*\n", f"__version__ = {version!r}\n", contents)

with open("pymatgen/core/__init__.py", "w") as f:
f.write(contents)
with open("pymatgen/core/__init__.py", "w") as file:
file.write(contents)

with open("setup.py") as f:
contents = f.read()
with open("setup.py") as file:
contents = file.read()
contents = re.sub(r"version=([^,]+),", f"version={version!r},", contents)

with open("setup.py", "w") as f:
f.write(contents)
with open("setup.py", "w") as file:
file.write(contents)


@task
Expand All @@ -203,12 +193,12 @@ def release_github(ctx, version):

:param ctx:
"""
with open("CHANGES.rst") as f:
contents = f.read()
toks = re.split(r"\-+", contents)
desc = toks[1].strip()
toks = desc.split("\n")
desc = "\n".join(toks[:-1]).strip()
with open("CHANGES.rst") as file:
contents = file.read()
tokens = re.split(r"\-+", contents)
desc = tokens[1].strip()
tokens = desc.split("\n")
desc = "\n".join(tokens[:-1]).strip()
payload = {
"tag_name": f"v{version}",
"target_commitish": "master",
Expand Down