Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 5, 2024
1 parent aa7bc77 commit 0f3563d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 41 deletions.
4 changes: 3 additions & 1 deletion atomdb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ def load_all(elem, nexc=0, dataset=DEFAULT_DATASET, datapath=DEFAULT_DATAPATH):
with open(file, "rb") as f:
msg = unpack_msg(f)
# Convert raw bytes back to numpy arrays, initialize the Species instance, store it
species.append(Species(**{k: frombuffer(v) if isinstance(v, bytes) else v for k, v in msg.items()}))
species.append(
Species(**{k: frombuffer(v) if isinstance(v, bytes) else v for k, v in msg.items()})
)
return species


Expand Down
4 changes: 1 addition & 3 deletions atomdb/datasets/uhf_augccpvdz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def eval_orb_ked(one_density_matrix, basis, points, transform=None):
"Adapted from Gbasis"
orbt_ked = 0
for orders in np.identity(3, dtype=int):
deriv_orb_eval_one = evaluate_deriv_basis(
basis, points, orders, transform=transform
)
deriv_orb_eval_one = evaluate_deriv_basis(basis, points, orders, transform=transform)
deriv_orb_eval_two = deriv_orb_eval_one # orders_one == orders_two
density = one_density_matrix.dot(deriv_orb_eval_two)
density *= deriv_orb_eval_one
Expand Down
40 changes: 27 additions & 13 deletions atomdb/promolecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ def make_promolecule(
# Handle default multiplicity parameters
if mults is None:
# Force non-int charge to be integer here; it will be overwritten below.
mults = [MULTIPLICITIES[int(np.round(atnum - charge))] for (atnum, charge) in zip(atnums, charges)]
mults = [
MULTIPLICITIES[int(np.round(atnum - charge))]
for (atnum, charge) in zip(atnums, charges)
]

# Construct linear combination of species
promol = Promolecule()
Expand All @@ -424,16 +427,18 @@ def make_promolecule(
promol.append(specie, coord, 1.0)
continue
except FileNotFoundError:
warn("Unable to load species corresponding to `charge, mult`; "
"generating species via linear combination of other species'")
warn(
"Unable to load species corresponding to `charge, mult`; "
"generating species via linear combination of other species'"
)

# Non-integer charge and multiplicity
#
nelec = atnum - charge
nspin = np.sign(mult) * (abs(mult) - 1)
# Get all candidates for linear combination
species_list = load_all(atom, dataset=dataset, datapath=datapath)
for specie in species_list[:len(species_list)]:
for specie in species_list[: len(species_list)]:
if specie.nspin > 0:
specie_neg_spinpol = deepcopy(specie)
specie_neg_spinpol.spinpol = -1
Expand All @@ -445,11 +450,14 @@ def make_promolecule(
energies = np.asarray([t.energy for t in ts], dtype=float)
result = linprog(
energies,
A_eq=np.asarray([
[1 for t in ts],
[t.nelec for t in ts],
[t.nspin * t.spinpol for t in ts],
], dtype=float),
A_eq=np.asarray(
[
[1 for t in ts],
[t.nelec for t in ts],
[t.nspin * t.spinpol for t in ts],
],
dtype=float,
),
b_eq=np.asarray([1, nelec, nspin], dtype=float),
bounds=(0, 1),
)
Expand Down Expand Up @@ -508,9 +516,15 @@ def _cart_to_bary(x0, y0, s1, s2, s3):
r"""Helper function for computing barycentric coordinates."""
x1, x2, x3 = s1.nelec, s2.nelec, s3.nelec
y1, y2, y3 = s1.nspin, s2.nspin, s3.nspin
lambda1 = ((y2 - y3) * (x0 - x3) + (x3 - x2) * (y0 - y3) /
(y2 - y3) * (x1 - x3) + (x3 - x2) * (y1 - y3))
lambda2 = ((y3 - y1) * (x0 - x3) + (x1 - x3) * (y0 - y3) /
(y2 - y3) * (x1 - x3) + (x3 - x2) * (y1 - y3))
lambda1 = (
(y2 - y3) * (x0 - x3)
+ (x3 - x2) * (y0 - y3) / (y2 - y3) * (x1 - x3)
+ (x3 - x2) * (y1 - y3)
)
lambda2 = (
(y3 - y1) * (x0 - x3)
+ (x1 - x3) * (y0 - y3) / (y2 - y3) * (x1 - x3)
+ (x3 - x2) * (y1 - y3)
)
lambda3 = 1 - lambda1 - lambda2
return (lambda1, lambda2, lambda3)
69 changes: 45 additions & 24 deletions atomdb/test/test_promolecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@
pytest.param(
{
"atnums": [1, 1],
"coords": np.asarray([
[ 0., 0., 0.],
[ 0., 0., 1.],
], dtype=float),
"coords": np.asarray(
[
[0.0, 0.0, 0.0],
[0.0, 0.0, 1.0],
],
dtype=float,
),
"dataset": "slater",
},
id="H2 default charge/mult",
Expand All @@ -48,10 +51,13 @@
{
"atnums": [6, 6],
"charges": [1, -1],
"coords": np.asarray([
[ 0., 0., 0.],
[ 0., 0., 1.],
], dtype=float),
"coords": np.asarray(
[
[0.0, 0.0, 0.0],
[0.0, 0.0, 1.0],
],
dtype=float,
),
"dataset": "slater",
},
id="C2 +/-1 charge, default mult",
Expand All @@ -61,10 +67,13 @@
"atnums": [6, 6],
"charges": [0.5, -0.5],
"mults": [1, -1],
"coords": np.asarray([
[ 0., 0., 0.],
[ 0., 0., 1.],
], dtype=float),
"coords": np.asarray(
[
[0.0, 0.0, 0.0],
[0.0, 0.0, 1.0],
],
dtype=float,
),
"dataset": "slater",
},
id="C2 +/-0.5 charge",
Expand All @@ -74,9 +83,12 @@
"atnums": [4],
"charges": [1.2],
"mults": [1.2],
"coords": np.asarray([
[ 0., 0., 0.],
], dtype=float),
"coords": np.asarray(
[
[0.0, 0.0, 0.0],
],
dtype=float,
),
"dataset": "uhf_augccpvdz",
},
id="Be floating point charge/floating point mult",
Expand All @@ -86,9 +98,12 @@
"atnums": [4],
"charges": [1.2],
"mults": [1],
"coords": np.asarray([
[ 0., 0., 0.],
], dtype=float),
"coords": np.asarray(
[
[0.0, 0.0, 0.0],
],
dtype=float,
),
"dataset": "uhf_augccpvdz",
},
id="Be floating point charge/integer mult",
Expand All @@ -98,9 +113,12 @@
"atnums": [4],
"charges": [1.2],
"mults": [-1.2],
"coords": np.asarray([
[ 0., 0., 0.],
], dtype=float),
"coords": np.asarray(
[
[0.0, 0.0, 0.0],
],
dtype=float,
),
"dataset": "uhf_augccpvdz",
},
id="Be floating point charge/floating point mult (neg)",
Expand All @@ -110,9 +128,12 @@
"atnums": [4],
"charges": [1.2],
"mults": [-1],
"coords": np.asarray([
[ 0., 0., 0.],
], dtype=float),
"coords": np.asarray(
[
[0.0, 0.0, 0.0],
],
dtype=float,
),
"dataset": "uhf_augccpvdz",
},
id="Be floating point charge/integer mult (neg)",
Expand Down

0 comments on commit 0f3563d

Please sign in to comment.