Skip to content

Commit

Permalink
Merge pull request #157 from Spin-Chemistry-Labs/131-move-anisotropy-…
Browse files Browse the repository at this point in the history
…and-mary-to-a-new-experimentspy-module

131 move anisotropy and mary to a new experimentspy module
  • Loading branch information
vatai authored Aug 17, 2024
2 parents f5b900f + 4afb2c7 commit 8deda6d
Show file tree
Hide file tree
Showing 50 changed files with 6,804 additions and 675 deletions.
File renamed without changes.
42 changes: 42 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Coverage

on: push
jobs:
run-radicalpy-coverage:
name: Run coverage on RadicalPy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python "3.11" 🐍
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: 'pip'
- name: Install packages 📦
run: >-
python -m
pip install -r requirements.txt
- name: Install coverage
run: >-
python -m
pip install coverage
- name: Reset coverage
run: >-
coverage erase
- name: Run coverage
run: >-
coverage run -a -m
unittest
discover -v
- name: Run examples
run: >-
for file in $(ls examples/aniso*.py); do
PYTHONPATH=. coverage run -a $file --fast
done
- name: Create report
run: >-
coverage report && coverage xml && ls -lrt
- name: Code Coverage Report
uses: irongut/[email protected]
with:
filename: coverage.xml
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Lint

on: [push, pull_request]
on: [push]

jobs:
lint:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Set up Python ${{ matrix.python }} 🐍
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
cache: 'pip'
Expand All @@ -25,3 +25,12 @@ jobs:
python -m
unittest
discover -v
- name: Run examples
if: runner.os == 'Linux'
# This is bash.
# Need a separate branch to iterate over files on Windows.
run: >-
for file in $(ls examples/*.py); do
echo "Running example: $file"
PYTHONPATH=. python $file --fast
done
16 changes: 10 additions & 6 deletions examples/T1_T2_relaxation_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
aqueous_glycerol_viscosity,
rotational_correlation_time_for_protein,
)
from radicalpy.utils import is_fast_run


def main():
Expand All @@ -26,9 +27,9 @@ def main():
plt.axis("on")
plt.rc("axes", edgecolor="k")
for t in temperatures:
plt.plot(ratio, eta[t] * f, label=f"{t}$^\circ$C")
plt.plot(ratio, eta[t] * f, label=f"{t}$^\\circ$C")
plt.xlabel("Glycerol fraction", size=14)
plt.ylabel("Viscosity ($mN \, s \, m^{-2}$)", size=14)
plt.ylabel(r"Viscosity ($mN \, s \, m^{-2}$)", size=14)
plt.legend()
plt.tick_params(labelsize=14)
path = __file__[:-3] + f"_{0}.png"
Expand All @@ -47,7 +48,7 @@ def main():
plt.axis("on")
plt.rc("axes", edgecolor="k")
for t in temperatures:
plt.plot(ratio, tau_c[t] * f2, label=f"{t}$^\circ$C")
plt.plot(ratio, tau_c[t] * f2, label=f"{t}$^\\circ$C")
plt.xlabel("Glycerol fraction", size=14)
plt.ylabel(r"$\tau _C$ ($\mu s$)", size=14)
plt.legend()
Expand All @@ -73,7 +74,7 @@ def main():
plt.axis("on")
plt.rc("axes", edgecolor="k")
for t in temperatures:
plt.plot(ratio, 1 / t1[t], label=f"{t}$^\circ$C")
plt.plot(ratio, 1 / t1[t], label=f"{t}$^\\circ$C")
plt.xlabel("Glycerol fraction", size=14)
plt.ylabel(r"1 / T1 ($s$)", size=14)
plt.legend()
Expand All @@ -86,7 +87,7 @@ def main():
plt.axis("on")
plt.rc("axes", edgecolor="k")
for t in temperatures:
plt.plot(ratio, 1 / t2[t], label=f"{t}$^\circ$C")
plt.plot(ratio, 1 / t2[t], label=f"{t}$^\\circ$C")
plt.xlabel("Glycerol fraction", size=14)
plt.ylabel(r"1 / T2 ($s$)", size=14)
plt.legend()
Expand All @@ -96,4 +97,7 @@ def main():


if __name__ == "__main__":
main()
if is_fast_run():
main() # quick enough
else:
main()
23 changes: 16 additions & 7 deletions examples/anisotropy_3d_polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@
import numpy as np

import radicalpy as rp
from radicalpy.experiments import anisotropy
from radicalpy.simulation import State
from radicalpy.utils import is_fast_run


def main():
theta = np.linspace(0, np.pi, 17)
phi = np.linspace(0, 2 * np.pi, 32)
# def main(theta_steps=35, phi_steps=58, tmax=15e-6, dt=5e-9):
def main(theta_steps=17, phi_steps=32, tmax=5e-6, dt=5e-9):
theta = np.linspace(0, np.pi, theta_steps)
phi = np.linspace(0, 2 * np.pi, phi_steps)

flavin = rp.simulation.Molecule.fromdb("flavin_anion", ["N5", "N10"])
Z = rp.simulation.Molecule("zorro", [])
sim = rp.simulation.HilbertSimulation([flavin, Z])

time = np.arange(0, 5e-6, 5e-9)
time = np.arange(0, tmax, dt)
B0 = 0.05
k = 1e6

results = sim.anisotropy(
results = anisotropy(
sim,
init_state=State.SINGLET,
obs_state=State.SINGLET,
time=time,
Expand All @@ -41,10 +45,15 @@ def main():
print(f"{Y_av=}")
print(f"{delta_phi_s=}")
print(f"{gamma_s=}")
plt.show()
# plt.show()
path = __file__[:-3] + f"_{3}.png"
plt.savefig(path)

return 0


if __name__ == "__main__":
main()
if is_fast_run():
main(theta_steps=7, phi_steps=6, tmax=10e-6, dt=1e-6)
else:
main()
19 changes: 12 additions & 7 deletions examples/anisotropy_3d_polar_paper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from radicalpy import kinetics, relaxation
from radicalpy.experiments import anisotropy
from radicalpy.simulation import State
from radicalpy.utils import is_fast_run


def main():

def main(theta_steps=35, phi_steps=58, tmax=15e-6, dt=5e-9):
fad_n5_hfc = np.array(
[
[0.280, -0.138, 0.678],
Expand All @@ -21,14 +21,14 @@ def main():

dipolar = rp.estimations.dipolar_interaction_anisotropic(r=22e-10)

theta = np.linspace(0, np.pi, 35)
phi = np.linspace(0, 2 * np.pi, 58)
theta = np.linspace(0, np.pi, theta_steps)
phi = np.linspace(0, 2 * np.pi, phi_steps)

flavin = rp.simulation.Molecule.fromisotopes(isotopes=["14N"], hfcs=[fad_n5_hfc])
Z = rp.simulation.Molecule("zorro", [])
sim = rp.simulation.HilbertSimulation([flavin, Z])

time = np.arange(0, 15e-6, 5e-9)
time = np.arange(0, tmax, dt)
B0 = 0.05
k = 1e6

Expand Down Expand Up @@ -58,10 +58,15 @@ def main():
print(f"{Y_av=}")
print(f"{delta_phi_s=}")
print(f"{gamma_s=}")
plt.show()
# plt.show()
path = __file__[:-3] + f"_{3}.png"
plt.savefig(path)

return 0


if __name__ == "__main__":
main()
if is_fast_run():
main(theta_steps=7, phi_steps=6, tmax=10e-6, dt=1e-6)
else:
main()
19 changes: 12 additions & 7 deletions examples/anisotropy_3d_polar_paper_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from radicalpy import kinetics, relaxation
from radicalpy.experiments import anisotropy
from radicalpy.simulation import State
from radicalpy.utils import is_fast_run


def main():

def main(theta_steps=35, phi_steps=58, tmax=15e-6, dt=5e-9):
fad_n5_hfc = np.array(
[
[0.280, -0.138, 0.678],
Expand Down Expand Up @@ -38,14 +38,14 @@ def main():
* rp.data.Isotope("E").gamma_mT
)

theta = np.linspace(0, np.pi, 35)
phi = np.linspace(0, 2 * np.pi, 58)
theta = np.linspace(0, np.pi, theta_steps)
phi = np.linspace(0, 2 * np.pi, phi_steps)

flavin = rp.simulation.Molecule.fromisotopes(isotopes=["14N"], hfcs=[fad_n5_hfc])
trp = rp.simulation.Molecule.fromisotopes(isotopes=["1H"], hfcs=[trp_hbeta_hfc])
sim = rp.simulation.HilbertSimulation([flavin, trp])

time = np.arange(0, 15e-6, 5e-9)
time = np.arange(0, tmax, dt)
B0 = 0.05
k = 1e6

Expand Down Expand Up @@ -75,10 +75,15 @@ def main():
print(f"{Y_av=}")
print(f"{delta_phi_s=}")
print(f"{gamma_s=}")
plt.show()
# plt.show()
path = __file__[:-3] + f"_{3}.png"
plt.savefig(path)

return 0


if __name__ == "__main__":
main()
if is_fast_run():
main(theta_steps=7, phi_steps=6, tmax=10e-6, dt=1e-6)
else:
main()
87 changes: 0 additions & 87 deletions examples/bhalf_data_comparison.py

This file was deleted.

Loading

0 comments on commit 8deda6d

Please sign in to comment.