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

upgrade lint and test checks #25

Merged
merged 34 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
99d3176
add from __future__ import annotations
htz1992213 Feb 4, 2024
5540f89
Update test_volume.py
htz1992213 Feb 4, 2024
043fe22
typing to annotations
htz1992213 Feb 4, 2024
5d949fe
typing to future annotations 2
htz1992213 Feb 4, 2024
9cd855e
drop UTF-8 encoding declaration
htz1992213 Feb 4, 2024
38b3448
add more annotations imports
htz1992213 Feb 4, 2024
27511ef
lint fixes 1
htz1992213 Feb 4, 2024
4e6e6d8
ruff 1
htz1992213 Feb 4, 2024
e1ba1e3
ruff 2
htz1992213 Feb 4, 2024
2f886d9
self.assertAlmostEqual to assert_allclose
htz1992213 Feb 4, 2024
8b6cf53
try import numpy twice?
htz1992213 Feb 5, 2024
ec8ebc3
update test_msd forms
htz1992213 Feb 5, 2024
6d2e8b0
update test_forcefield forms
htz1992213 Feb 5, 2024
a9dc5d9
update test_conductivity forms
htz1992213 Feb 5, 2024
362fcb0
ruff fix conductivity
htz1992213 Feb 5, 2024
c81b502
ruff fix coordination
htz1992213 Feb 5, 2024
082f884
ruff fixes
htz1992213 Feb 5, 2024
73d8a33
ruff fixes 2
htz1992213 Feb 5, 2024
80325cf
ruff doc conf
htz1992213 Feb 5, 2024
a6cc3fd
more ruff fixes
htz1992213 Feb 5, 2024
4ab775d
more ruff fixes 2
htz1992213 Feb 5, 2024
54953f2
update forcefield test forms
htz1992213 Feb 5, 2024
f9eda4c
add absolute error to msd test
htz1992213 Feb 5, 2024
f5eb2db
ruff fixes 3
htz1992213 Feb 5, 2024
7bd1704
revert assertion change
htz1992213 Feb 5, 2024
dd99bc4
finish ruff fixes
htz1992213 Feb 5, 2024
e8a094c
final ruff fixes 2
htz1992213 Feb 5, 2024
fe7c547
set atol for more assert_allclose
htz1992213 Feb 5, 2024
d878a1c
fix test raises
htz1992213 Feb 5, 2024
867001b
lint
htz1992213 Feb 5, 2024
6f9d3d5
drop noreturn
htz1992213 Feb 5, 2024
5da174a
Update pyproject.toml
htz1992213 Feb 5, 2024
e7929de
change assertion format
htz1992213 Feb 5, 2024
bcc3572
add additional tol for volume
htz1992213 Feb 5, 2024
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
8 changes: 4 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Configuration file for the Sphinx documentation builder.
"""Configuration file for the Sphinx documentation builder."""
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
Expand All @@ -10,10 +10,10 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
from __future__ import annotations

import os
import sys
import sphinx_rtd_theme, sphinx_autodoc_typehints
from typing import List

sys.path.insert(0, os.path.abspath("../../mdgo"))

Expand Down Expand Up @@ -55,7 +55,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns: List[str] = []
exclude_patterns: list[str] = []


# -- Options for HTML output -------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions mdgo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# coding: utf-8
# Copyright (c) Tingzheng Hou.
# Distributed under the terms of the MIT License.

"""
This package contains core modules and classes molecular dynamics simulation setup and analysis.
"""
"""This package contains core modules and classes molecular dynamics simulation setup and analysis."""

from __future__ import annotations

__author__ = "Mdgo Development Team"
__email__ = "tingzheng_hou@berkeley.edu"
__maintainer__ = "Tingzheng Hou"
Expand Down
33 changes: 17 additions & 16 deletions mdgo/conductivity.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# coding: utf-8
# Copyright (c) Tingzheng Hou.
# Distributed under the terms of the MIT License.

"""
This module implements functions to calculate the ionic conductivity.
"""
from typing import Union
"""This module implements functions to calculate the ionic conductivity."""

from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np
from tqdm.auto import tqdm
from scipy import stats
from MDAnalysis import Universe, AtomGroup
from tqdm.auto import tqdm

from mdgo.msd import msd_fft

if TYPE_CHECKING:
from MDAnalysis import AtomGroup, Universe

__author__ = "Kara Fong, Tingzheng Hou"
__version__ = "0.3.0"
__maintainer__ = "Tingzheng Hou"
Expand All @@ -26,10 +28,10 @@ def calc_cond_msd(
anions: AtomGroup,
cations: AtomGroup,
run_start: int,
cation_charge: Union[int, float] = 1,
anion_charge: Union[int, float] = -1,
cation_charge: float = 1,
anion_charge: float = -1,
) -> np.ndarray:
"""Calculates the conductivity "mean square displacement" over time
"""Calculates the conductivity "mean square displacement" over time.

Note:
Coordinates must be unwrapped (in dcd file when creating MDAnalysis Universe)
Expand All @@ -51,15 +53,14 @@ def calc_cond_msd(
anion_list = anions.split("residue")
# compute sum over all charges and positions
qr = []
for ts in tqdm(u.trajectory[run_start:]):
for _ts in tqdm(u.trajectory[run_start:]):
qr_temp = np.zeros(3)
for anion in anion_list:
qr_temp += anion.center_of_mass() * anion_charge
for cation in cation_list:
qr_temp += cation.center_of_mass() * cation_charge
qr.append(qr_temp)
msd = msd_fft(np.array(qr))
return msd
return msd_fft(np.array(qr))


def get_beta(
Expand Down Expand Up @@ -127,14 +128,14 @@ def choose_msd_fitting_region(
def conductivity_calculator(
time_array: np.ndarray,
cond_array: np.ndarray,
v: Union[int, float],
v: float,
name: str,
start: int,
end: int,
T: Union[int, float],
T: float,
units: str = "real",
) -> float:
"""Calculates the overall conductivity of the system
"""Calculates the overall conductivity of the system.

Args:
time_array: times at which position data was collected in the simulation
Expand Down
Loading
Loading