Skip to content

Commit

Permalink
Merge branch 'master' into ele_band_color
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Jan 26, 2023
2 parents 27ab3b1 + cd37811 commit 30e42b2
Show file tree
Hide file tree
Showing 504 changed files with 48,598 additions and 118,458 deletions.
11 changes: 11 additions & 0 deletions CHANGES.rst
@@ -1,4 +1,15 @@
Change log
==========

v2023.1.20
----------
* Passthrough kwargs support for Structure.from_file and Structure.from_str
* Allow the `frac_tolerance` to be specified for rounding coordinates in CifParser.
* PR #2803 from @amkrajewski add_weightbasedfunctions
When working with metallic alloys, weight-fraction-based notations such as Ti64 / Ti-6V-4Al or NiTiNOL60 / Ni-40Ti are commonly employed in both industrial specifications and scientific literature. Regardless of the numerous downsides of this situation, including errors in scientific experiments or NLP-parsing when they are mistaken for atomic fractions or chemical formulas, being able to create a Composition object from them (under correct interpretation) would be a useful pymatgen feature.
- Composition class method to initialize it from a dictionary of weight fractions
- Composition property giving a dictionary of weight fractions
- concise tests for the two above were added
QChem: translate DMSO name in smd_solvent

v2023.1.9
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -30,7 +30,7 @@ Pymatgen is free to use. However, we also welcome your help to improve this libr
- Bug reports or feature requests: Please submit a [GitHub Issue](https://github.com/materialsproject/pymatgen/issues).
- Code contributions via [pull requests](https://github.com/materialsproject/pymatgen/pulls) are welcome.
- For help with usage that is unrelated to bugs or feature requests, please use the `pymatgen` [MatSci page](https://discuss.matsci.org/c/pymatgen).
- [`matgenb`](https://matgenb.materialsvirtuallab.org) provides some Jupyter notebooks demonstrating functionality.
- [`matgenb`](https://github.com/materialsvirtuallab/matgenb#introduction) provides some Jupyter notebooks demonstrating functionality.
- Follow us on [Twitter](https://twitter.com/pymatgen) to get news and tips.

## Why use pymatgen?
Expand Down
4 changes: 2 additions & 2 deletions dev_scripts/chemenv/equivalent_indices.py
Expand Up @@ -7,15 +7,15 @@

from __future__ import annotations

import numpy as np

__author__ = "David Waroquiers"
__copyright__ = "Copyright 2012, The Materials Project"
__version__ = "2.0"
__maintainer__ = "David Waroquiers"
__email__ = "david.waroquiers@gmail.com"
__date__ = "Feb 20, 2016"

import numpy as np

if __name__ == "__main__":

cg_symbol = "O:6"
Expand Down
14 changes: 7 additions & 7 deletions dev_scripts/chemenv/explicit_permutations.py
Expand Up @@ -8,13 +8,6 @@

from __future__ import annotations

__author__ = "David Waroquiers"
__copyright__ = "Copyright 2012, The Materials Project"
__version__ = "2.0"
__maintainer__ = "David Waroquiers"
__email__ = "david.waroquiers@gmail.com"
__date__ = "Feb 20, 2016"

import itertools
import json
import os
Expand All @@ -30,6 +23,13 @@
LocalGeometryFinder,
)

__author__ = "David Waroquiers"
__copyright__ = "Copyright 2012, The Materials Project"
__version__ = "2.0"
__maintainer__ = "David Waroquiers"
__email__ = "david.waroquiers@gmail.com"
__date__ = "Feb 20, 2016"


class Algo:
pass
Expand Down
44 changes: 23 additions & 21 deletions dev_scripts/chemenv/explicit_permutations_plane_algorithm.py
Expand Up @@ -40,23 +40,23 @@
if algo.algorithm_type != "SEPARATION_PLANE":
raise ValueError("WRONG ALGORITHM !")

newalgos = []
new_algos = []

ialgo = 1
for sepplanealgo in cg._algorithms:
print(f"In ialgo = {ialgo:d}/{len(cg._algorithms):d}")
for sep_plane_algo in cg._algorithms:
print(f"In {ialgo = :d}/{len(cg._algorithms):d}")
ialgo += 1
if sepplanealgo.algorithm_type != "SEPARATION_PLANE":
if sep_plane_algo.algorithm_type != "SEPARATION_PLANE":
raise ValueError("Should all be separation plane")

permsonfile = f"Permutations on file in this algorithm ({len(sepplanealgo._permutations):d}) "
print(permsonfile)
print(sepplanealgo._permutations)
permutations = sepplanealgo.safe_separation_permutations(
ordered_plane=sepplanealgo.ordered_plane, ordered_point_groups=sepplanealgo.ordered_point_groups
perms_on_file = f"Permutations on file in this algorithm ({len(sep_plane_algo._permutations):d}) "
print(perms_on_file)
print(sep_plane_algo._permutations)
permutations = sep_plane_algo.safe_separation_permutations(
ordered_plane=sep_plane_algo.ordered_plane, ordered_point_groups=sep_plane_algo.ordered_point_groups
)

sepplanealgo._permutations = permutations
sep_plane_algo._permutations = permutations

print(f"Test permutations ({len(permutations):d}) :")
print(permutations)
Expand All @@ -72,12 +72,14 @@
# Setting up the plane of separation
local_plane = None
found = False
for npoints in range(sepplanealgo.minimum_number_of_points, min(sepplanealgo.maximum_number_of_points, 4) + 1):
for n_points in range(
sep_plane_algo.minimum_number_of_points, min(sep_plane_algo.maximum_number_of_points, 4) + 1
):
if found:
break
for ipoints in itertools.combinations(sepplanealgo.plane_points, npoints):
for ipoints in itertools.combinations(sep_plane_algo.plane_points, n_points):
points_combination = [lgf.local_geometry.coords[ipoint] for ipoint in ipoints]
if npoints == 2:
if n_points == 2:
if collinear(
points_combination[0], points_combination[1], lgf.local_geometry.central_site, tolerance=0.25
):
Expand All @@ -87,15 +89,15 @@
)
found = True
break
elif npoints == 3:
elif n_points == 3:
if collinear(points_combination[0], points_combination[1], points_combination[2], tolerance=0.25):
continue
local_plane = Plane.from_3points(
points_combination[0], points_combination[1], points_combination[2]
)
found = True
break
elif npoints > 3:
elif n_points > 3:
local_plane = Plane.from_npoints(points_combination, best_fit="least_square_distance")
found = True
break
Expand All @@ -106,7 +108,7 @@
# Actual test of the permutations
cgsm = lgf._cg_csm_separation_plane(
coordination_geometry=cg,
sepplane=sepplanealgo,
sepplane=sep_plane_algo,
local_plane=local_plane,
plane_separations=[],
dist_tolerances=[0.05, 0.1, 0.2, 0.3],
Expand All @@ -124,7 +126,7 @@

print("Continuous symmetry measures")
print(csms)
csms_with_recorded_permutation = []
csms_with_recorded_permutation: list[float] = []
explicit_permutations = []
for icsm, csm in enumerate(csms):
found = False
Expand All @@ -137,16 +139,16 @@
csms_with_recorded_permutation.append(csm)
explicit_permutations.append(sep_perms[icsm])

print(permsonfile)
print(perms_on_file)
print(f"Permutations found ({len(explicit_permutations):d}) : ")
print(explicit_permutations)
sepplanealgo.explicit_permutations = explicit_permutations
newalgos.append(sepplanealgo)
sep_plane_algo.explicit_permutations = explicit_permutations
new_algos.append(sep_plane_algo)

# Write update geometry file ?
test = input('Save it ? ("y" to confirm)')
if test == "y":
cg._algorithms = newalgos
cg._algorithms = new_algos
cg_dict = cg.as_dict()
with open(f"../coordination_geometries_files_new/{cg_symbol}.json", "w") as f:
json.dump(cg_dict, f)
21 changes: 14 additions & 7 deletions dev_scripts/chemenv/get_plane_permutations_optimized.py
Expand Up @@ -48,8 +48,15 @@ def prt2(string, printing_volume):


# Iterator function for the random permutations
def random_permutations_iterator(initial_permutation, npermutations):
for _ in range(npermutations):
def random_permutations_iterator(initial_permutation, n_permutations):
"""
It takes a list and returns an iterator that yields random permutations of that list
Args:
initial_permutation: the initial permutation of the data
n_permutations: the number of permutations to generate
"""
for _ in range(n_permutations):
shuffle(initial_permutation)
yield initial_permutation

Expand Down Expand Up @@ -157,7 +164,7 @@ def random_permutations_iterator(initial_permutation, npermutations):

cg = all_cg[cg_symbol]

print(f'Getting explicit permutations for geometry "{cg.name}" (symbol : "{cg_symbol}")\n')
print(f"Getting explicit permutations for geometry {cg.name!r} (symbol : {cg_symbol!r})\n")

# Setup of the local geometry finder
lgf = LocalGeometryFinder()
Expand Down Expand Up @@ -274,8 +281,8 @@ def random_permutations_iterator(initial_permutation, npermutations):

while True:
test = input(
f'Get the explicit optimized permutations for geometry "{cg.name}" (symbol : '
f'"{cg_symbol}") ? ("y" to confirm, "q" to quit)\n'
f"Get the explicit optimized permutations for geometry {cg.name!r} (symbol : "
f'{cg_symbol!r}) ? ("y" to confirm, "q" to quit)\n'
)
if test not in ["y", "q"]:
print("Wrong key, try again")
Expand All @@ -285,7 +292,7 @@ def random_permutations_iterator(initial_permutation, npermutations):
elif test == "q":
exit()
# 2. Optimization of the permutations
print(f'Getting explicit optimized permutations for geometry "{cg.name}" (symbol : "{cg_symbol}")\n')
print(f"Getting explicit optimized permutations for geometry {cg.name!r} (symbol : {cg_symbol!r})\n")
perms_used_algos = [dict() for algo in cg.algorithms]

# Loop on algorithms
Expand Down Expand Up @@ -424,7 +431,7 @@ def random_permutations_iterator(initial_permutation, npermutations):
algo.explicit_optimized_permutations = np.array(explicit_optimized_permutations)

test = input(
f'Save coordination geometry "{cg.name}" (symbol "{cg_symbol}") and new explicit and optimized '
f"Save coordination geometry {cg.name!r} (symbol {cg_symbol!r}) and new explicit and optimized "
'permutations ? ("y" to confirm)'
)
if test == "y":
Expand Down
8 changes: 4 additions & 4 deletions dev_scripts/chemenv/plane_multiplicity.py
Expand Up @@ -7,17 +7,17 @@

from __future__ import annotations

from pymatgen.analysis.chemenv.coordination_environments.coordination_geometries import (
AllCoordinationGeometries,
)

__author__ = "David Waroquiers"
__copyright__ = "Copyright 2012, The Materials Project"
__version__ = "2.0"
__maintainer__ = "David Waroquiers"
__email__ = "david.waroquiers@gmail.com"
__date__ = "Feb 20, 2016"

from pymatgen.analysis.chemenv.coordination_environments.coordination_geometries import (
AllCoordinationGeometries,
)

if __name__ == "__main__":

allcg = AllCoordinationGeometries()
Expand Down
27 changes: 14 additions & 13 deletions dev_scripts/chemenv/strategies/multi_weights_strategy_parameters.py
Expand Up @@ -7,13 +7,6 @@

from __future__ import annotations

__author__ = "David Waroquiers"
__copyright__ = "Copyright 2012, The Materials Project"
__version__ = "2.0"
__maintainer__ = "David Waroquiers"
__email__ = "david.waroquiers@gmail.com"
__date__ = "Feb 20, 2016"

import copy
import json
from typing import Sequence
Expand All @@ -40,6 +33,14 @@
from pymatgen.core.lattice import Lattice
from pymatgen.core.structure import Structure

__author__ = "David Waroquiers"
__copyright__ = "Copyright 2012, The Materials Project"
__version__ = "2.0"
__maintainer__ = "David Waroquiers"
__email__ = "david.waroquiers@gmail.com"
__date__ = "Feb 20, 2016"


allcg = AllCoordinationGeometries()


Expand Down Expand Up @@ -151,23 +152,23 @@ def figure_fractions(self, weights_options: dict, morphing_factors: Sequence[flo

def get_structure(self, morphing_factor):
lattice = Lattice.cubic(5.0)
myspecies = ["O"] * (self.coordination_geometry.coordination_number + 1)
myspecies[0] = "Cu"
species = ["O"] * (self.coordination_geometry.coordination_number + 1)
species[0] = "Cu"

coords = copy.deepcopy(self.abstract_geometry.points_wcs_ctwcc())
bare_points = self.abstract_geometry.bare_points_with_centre

for morphing in self.morphing_description:
if morphing["site_type"] == "neighbor":
isite = morphing["ineighbor"] + 1
i_site = morphing["ineighbor"] + 1
if morphing["expansion_origin"] == "central_site":
origin = bare_points[0]
vector = bare_points[isite] - origin
coords[isite] += vector * (morphing_factor - 1.0)
vector = bare_points[i_site] - origin
coords[i_site] += vector * (morphing_factor - 1.0)
else:
raise ValueError(f"Key \"site_type\" is {morphing['site_type']} while it can only be neighbor")

structure = Structure(lattice=lattice, species=myspecies, coords=coords, coords_are_cartesian=True)
structure = Structure(lattice=lattice, species=species, coords=coords, coords_are_cartesian=True)
return structure

def estimate_parameters(self, dist_factor_min, dist_factor_max, symmetry_measure_type="csm_wcs_ctwcc"):
Expand Down
16 changes: 8 additions & 8 deletions dev_scripts/chemenv/test_algos.py
Expand Up @@ -7,13 +7,6 @@

from __future__ import annotations

__author__ = "David Waroquiers"
__copyright__ = "Copyright 2012, The Materials Project"
__version__ = "2.0"
__maintainer__ = "David Waroquiers"
__email__ = "david.waroquiers@gmail.com"
__date__ = "Feb 20, 2016"

import itertools
import time
from math import factorial
Expand All @@ -29,6 +22,13 @@
LocalGeometryFinder,
)

__author__ = "David Waroquiers"
__copyright__ = "Copyright 2012, The Materials Project"
__version__ = "2.0"
__maintainer__ = "David Waroquiers"
__email__ = "david.waroquiers@gmail.com"
__date__ = "Feb 20, 2016"

if __name__ == "__main__":

allcg = AllCoordinationGeometries()
Expand Down Expand Up @@ -97,4 +97,4 @@
print(" => ", algos_results)
iperm += 1
t2 = time.clock()
print(f'Time to test {nperms} permutations for geometry "{cg.name}" (symbol "{cg_symbol}") : {t2 - t1:.2f} seconds')
print(f"Time to test {nperms} permutations for geometry {cg.name!r} (symbol {cg_symbol!r}) : {t2 - t1:.2f} seconds")
14 changes: 7 additions & 7 deletions dev_scripts/chemenv/test_algos_all_geoms.py
Expand Up @@ -7,13 +7,6 @@

from __future__ import annotations

__author__ = "David Waroquiers"
__copyright__ = "Copyright 2012, The Materials Project"
__version__ = "2.0"
__maintainer__ = "David Waroquiers"
__email__ = "david.waroquiers@gmail.com"
__date__ = "Feb 20, 2016"

import itertools
from math import factorial
from random import shuffle
Expand All @@ -26,6 +19,13 @@
LocalGeometryFinder,
)

__author__ = "David Waroquiers"
__copyright__ = "Copyright 2012, The Materials Project"
__version__ = "2.0"
__maintainer__ = "David Waroquiers"
__email__ = "david.waroquiers@gmail.com"
__date__ = "Feb 20, 2016"

if __name__ == "__main__":

allcg = AllCoordinationGeometries()
Expand Down

0 comments on commit 30e42b2

Please sign in to comment.