Skip to content

Commit 13c497c

Browse files
committed
feat: Convert arrays back to confs
1 parent 2d2d288 commit 13c497c

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

fmo_analysis/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '0.17.1'
1+
__version__ = '0.17.2'
22

33
import ham2spec

fmo_analysis/exciton.py

+15
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ def confs_to_arrays(confs: List[Dict]) -> Tuple[np.ndarray, np.ndarray, np.ndarr
6262
return hams, mus, rs
6363

6464

65+
def arrays_to_confs(hams: np.ndarray, mus: np.ndarray, rs: np.ndarray):
66+
"""Convert arrays to a list of confs"""
67+
n_confs, n_pigs, _ = hams.shape
68+
confs = list()
69+
for i in range(n_confs):
70+
ham = hams[i]
71+
mus_single = mus[i]
72+
rs_single = rs[i]
73+
pigs = list()
74+
for j in range(n_pigs):
75+
pigs.append(Pigment(rs_single[j], mus_single[j]))
76+
confs.append({"ham": ham, "pigs": pigs})
77+
return confs
78+
79+
6580
def stick_spectrum(config, ham, pigs):
6681
"""Computes the stick spectra and eigenvalues/eigenvectors for the system."""
6782
mus, rs = pigs_to_arrays(pigs)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fmo_analysis"
3-
version = "0.17.1"
3+
version = "0.17.2"
44
description = ""
55
authors = ["Zach Mitchell <zmitchell@fastmail.com>"]
66

tests/test_computation.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from fmo_analysis import exciton, util
22
import numpy.testing as npt
33
from pytest import raises
4+
from numpy.random import random
45

56

67
def test_can_construct_config():
@@ -163,4 +164,14 @@ def test_computes_het_broadened_spectrum_from_hams(config, ham, pigments, abs, c
163164

164165
def test_broadened_spec_isnt_readonly(config, stick_spec):
165166
b_spec = exciton.broadened_spectrum_from_stick(config, stick_spec)
166-
b_spec["abs"] *= 0
167+
b_spec["abs"] *= 0
168+
169+
170+
def test_array_to_conf_conversion():
171+
dummy_hams = random(size=(100, 8, 8))
172+
dummy_mus = random(size=(100, 8, 3))
173+
dummy_rs = random(size=(100, 8, 3))
174+
hams, mus, rs = exciton.confs_to_arrays(exciton.arrays_to_confs(dummy_hams, dummy_mus, dummy_rs))
175+
npt.assert_array_almost_equal(dummy_hams, hams, decimal=4)
176+
npt.assert_array_almost_equal(dummy_mus, mus, decimal=4)
177+
npt.assert_array_almost_equal(dummy_rs, rs, decimal=4)

0 commit comments

Comments
 (0)