Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d787e94
Refactor: Add __len__ method to AtomicSystem class
galjos Aug 5, 2024
f43393d
chore: Update setup.py with compiler directive for Python 3 compatibi…
galjos Aug 5, 2024
b2a9600
bug: Missing comma in setup.py
galjos Aug 5, 2024
7048666
chore: Update setup.py, compiler directive for Python 3 compatibility…
galjos Aug 6, 2024
229bfae
add a function which adds not defined optional keys in the directory …
stkroe Dec 11, 2024
d64f70a
use this new not_defined_optional_keys function
stkroe Dec 11, 2024
e7db465
add None in the if conditions to ensure that NoneType are not causing…
stkroe Dec 11, 2024
275b3dc
rewrite the not_defined_optional_keys function with __setitem__ metho…
stkroe Dec 11, 2024
cc1e059
add None in the function annotations
stkroe Dec 11, 2024
409a3be
if restart file and moldescriptor are empty it is not working because…
stkroe Dec 11, 2024
375eb49
target density was not defined for no_intra_molecular=False; now the …
stkroe Dec 11, 2024
dbdebbd
Merge pull request #109 from MolarVerse/feature/len_in_atomsys
97gamjak Dec 11, 2024
eac4dc1
Add .github/.pylint_cache on push event
github-actions[bot] Dec 11, 2024
dbba27d
add None as type for boolean assert_logging_with_exception
stkroe Dec 12, 2024
dffb1d0
update GitHub Actions to use setup-python@v5
galjos Dec 15, 2024
bfb0365
fix: Disable iteration over AtomicSystem object
galjos Dec 29, 2024
cfb5391
fix: Replace np.in1d with np.isin for improved index matching
galjos Dec 29, 2024
92e68ee
bugfix: delete atleast numpy function and handle input types directly.
galjos Dec 29, 2024
d52e3b1
fix: update setuptools dependency to latest version
galjos Dec 29, 2024
1b191f8
fix: pin setuptools to version 70.0.0 so that pytest.sh works
galjos Dec 29, 2024
8630902
Merge pull request #115 from MolarVerse/bugfix/atleast_1d
97gamjak Dec 30, 2024
5233c5b
Add .github/.pylint_cache on push event
github-actions[bot] Dec 30, 2024
ff076a9
add a function which adds not defined optional keys in the directory …
stkroe Dec 11, 2024
5ea4351
use this new not_defined_optional_keys function
stkroe Dec 11, 2024
d72d124
add None in the if conditions to ensure that NoneType are not causing…
stkroe Dec 11, 2024
5a97cbe
rewrite the not_defined_optional_keys function with __setitem__ metho…
stkroe Dec 11, 2024
6ae17a8
add None in the function annotations
stkroe Dec 11, 2024
d166c80
if restart file and moldescriptor are empty it is not working because…
stkroe Dec 11, 2024
ab32870
target density was not defined for no_intra_molecular=False; now the …
stkroe Dec 11, 2024
3e476c7
add None as type for boolean assert_logging_with_exception
stkroe Dec 12, 2024
736e5c9
update GitHub Actions to use setup-python@v5
galjos Dec 15, 2024
1a818ac
Merge branch 'bugfix/rdf_bugfix' of github.com:MolarVerse/PQAnalysis …
stkroe Jan 7, 2025
776737c
Update PQAnalysis/analysis/rdf/rdf.py
stkroe Jan 7, 2025
4acdbc8
Test of pqanalysis_input_file_reader
stkroe Jan 7, 2025
d486b1e
Test of rdf_input_file_reader.py
stkroe Jan 7, 2025
614df34
Merge branch 'bugfix/rdf_bugfix' of github.com:MolarVerse/PQAnalysis …
stkroe Jan 7, 2025
78aa426
Testing warnings needs assert_logging()
stkroe Jan 7, 2025
0eeebd0
Tests for rdfOutputFileReader:
stkroe Jan 7, 2025
6be6534
Implementation before mentioned suggestion to remove the brackets
stkroe Jan 7, 2025
03fd8ce
Added one line which was missing \n.
stkroe Jan 7, 2025
92f780c
Tests for rdf.py
stkroe Jan 8, 2025
ce61178
More t#est for rdf.py.
stkroe Jan 8, 2025
91fac6a
Correct typo in filename
stkroe Jan 8, 2025
41b626d
Test in _parse.py and delete in rdf.py a space
stkroe Jan 8, 2025
3050345
Create a example rdf
stkroe Jan 13, 2025
8e454f1
Topology bug solved if no moldescriptor or restart file was given
stkroe Jan 13, 2025
0b1efc5
example for rdf with and without restart file
stkroe Jan 13, 2025
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
Binary file modified .github/.pylint_cache/PQAnalysis_1.stats
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.x

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _version.py
.github/.pylint_cache/__*

.coverage
.coverage.*
coverage.xml
htmlcov/
.vscode
Expand Down
4 changes: 1 addition & 3 deletions PQAnalysis/analysis/rdf/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def rdf(input_file: str, md_format: MDEngineFormat | str = MDEngineFormat.PQ):
)

traj_reader = TrajectoryReader(
input_reader.traj_files,
md_format=md_format,
topology=topology
input_reader.traj_files, md_format=md_format, topology=topology
)

_rdf = RDF(
Expand Down
130 changes: 56 additions & 74 deletions PQAnalysis/analysis/rdf/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def __init__(
traj: Trajectory | TrajectoryReader,
reference_species: SelectionCompatible,
target_species: SelectionCompatible,
use_full_atom_info: bool = False,
no_intra_molecular: bool = False,
use_full_atom_info: bool | None = False,
no_intra_molecular: bool | None = False,
n_bins: PositiveInt | None = None,
delta_r: PositiveReal | None = None,
r_max: PositiveReal | None = None,
Expand All @@ -92,10 +92,10 @@ def __init__(
The reference species of the RDF analysis.
target_species : SelectionCompatible
The target species of the RDF analysis.
use_full_atom_info : bool, optional
use_full_atom_info : bool | None, optional
Whether to use the full atom information of the trajectory
or not, by default None (False).
no_intra_molecular : bool, optional
no_intra_molecular : bool | None, optional
Whether to exclude intra-molecular distances or not, by default None (False).
n_bins : PositiveInt | None, optional
number of bins, by default None
Expand Down Expand Up @@ -193,7 +193,6 @@ def __init__(
############################################
# Initialize Trajectory iterator/generator #
############################################

self.cells = traj.cells

if isinstance(traj, TrajectoryReader):
Expand All @@ -204,28 +203,26 @@ def __init__(
self.frame_generator = iter(traj)
else:
self.logger.error(
"Trajectory cannot be of length 0.",
exception=RDFError
"Trajectory cannot be of length 0.", exception=RDFError
)

self.first_frame = next(self.frame_generator)
self.topology = traj.topology

if traj.topology is not None:
self.topology = traj.topology
else:
self.topology = self.first_frame.topology

self._setup_bins(
n_bins=n_bins,
delta_r=delta_r,
r_max=r_max,
r_min=self.r_min
n_bins=n_bins, delta_r=delta_r, r_max=r_max, r_min=self.r_min
)

self.reference_indices = self.reference_selection.select(
self.topology,
self.use_full_atom_info
self.topology, self.use_full_atom_info
)

self.target_indices = self.target_selection.select(
self.topology,
self.use_full_atom_info
self.topology, self.use_full_atom_info
)

def _setup_bins(
Expand Down Expand Up @@ -286,9 +283,9 @@ def _setup_bins(
elif all([n_bins, delta_r, r_max]):
self.logger.error(
(
"It is not possible to specify all of n_bins, "
"delta_r and r_max in the same RDF analysis "
"as this would lead to ambiguous results."
"It is not possible to specify all of n_bins, "
"delta_r and r_max in the same RDF analysis "
"as this would lead to ambiguous results."
),
exception=RDFError
)
Expand All @@ -301,10 +298,7 @@ def _setup_bins(
self.delta_r = delta_r

self.r_max = self._calculate_r_max(
n_bins,
delta_r,
r_min,
self.cells
n_bins, delta_r, r_min, self.cells
)

self.n_bins, self.r_max = self._calculate_n_bins(
Expand Down Expand Up @@ -336,10 +330,7 @@ def _setup_bins(
self.delta_r = (self.r_max - self.r_min) / self.n_bins

self.bin_middle_points = self._setup_bin_middle_points(
self.n_bins,
self.r_min,
self.r_max,
self.delta_r
self.n_bins, self.r_min, self.r_max, self.delta_r
)

self.bins = np.zeros(self.n_bins)
Expand All @@ -356,13 +347,14 @@ def _check_trajectory_conditions(self):
"""

if not check_trajectory_pbc(
self.cells) and not check_trajectory_vacuum(self.cells):
self.cells
) and not check_trajectory_vacuum(self.cells):
self.logger.error(
(
"The provided trajectory is not fully periodic or "
"in vacuum, meaning that some frames are in vacuum "
"and others are periodic. This is not supported by "
"the RDF analysis."
"The provided trajectory is not fully periodic or "
"in vacuum, meaning that some frames are in vacuum "
"and others are periodic. This is not supported by "
"the RDF analysis."
),
exception=RDFError
)
Expand All @@ -376,10 +368,10 @@ def average_volume(self) -> PositiveReal:
def run(
self
) -> Tuple[Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray]:
Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray]:
"""
Runs the RDF analysis.

Expand Down Expand Up @@ -453,8 +445,7 @@ def _initialize_target_index_combinations(self):
residue_indices = self.topology.residue_atom_indices[
reference_index]
self.target_index_combinations.append(
np.setdiff1d(self.target_indices,
residue_indices)
np.setdiff1d(self.target_indices, residue_indices)
)

def _calculate_bins(self):
Expand All @@ -469,9 +460,11 @@ def _calculate_bins(self):
calculated from these distances.
"""

for frame in tqdm(self.frame_generator,
for frame in tqdm(
self.frame_generator,
total=self.n_frames,
disable=not with_progress_bar):
disable=not with_progress_bar
):
for i, reference_index in enumerate(self.reference_indices):

if self.no_intra_molecular:
Expand All @@ -483,25 +476,20 @@ def _calculate_bins(self):
target_positions = frame.pos[target_indices]

distances = distance(
reference_position,
target_positions,
frame.cell
reference_position, target_positions, frame.cell
)

self.bins += self._add_to_bins(
distances,
self.r_min,
self.delta_r,
self.n_bins
distances, self.r_min, self.delta_r, self.n_bins
)

def _finalize_run(
self
) -> Tuple[Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray]:
Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray]:
"""
Finalizes the RDF analysis after running.

Expand All @@ -526,8 +514,11 @@ def _finalize_run(
differential_bins : Np1DNumberArray
The differential bins of the RDF analysis based on the spherical shell model.
"""
if self.no_intra_molecular:
target_density = len(self.target_index_combinations[0])
else:
target_density = len(self.target_indices)

target_density = len(self.target_index_combinations[0])
target_density /= self._average_volume

norm = self._norm(
Expand All @@ -541,9 +532,7 @@ def _finalize_run(
self.normalized_bins = self.bins / norm

self.integrated_bins = self._integration(
self.bins,
len(self.reference_indices),
self.n_frames
self.bins, len(self.reference_indices), self.n_frames
)

self.normalized_bins2 = self.bins / target_density
Expand Down Expand Up @@ -704,11 +693,11 @@ def _check_r_max(cls, r_max: PositiveReal, cells: Cells) -> PositiveReal:
if check_trajectory_pbc(cells) and r_max > cls._infer_r_max(cells):
cls.logger.warning(
(
f"The calculated r_max {r_max} is larger "
"than the maximum allowed radius according "
"to the box vectors of the trajectory "
f"{cls._infer_r_max(cells)}. r_max will be "
"set to the maximum allowed radius."
f"The calculated r_max {r_max} is larger "
"than the maximum allowed radius according "
"to the box vectors of the trajectory "
f"{cls._infer_r_max(cells)}. r_max will be "
"set to the maximum allowed radius."
),
)

Expand All @@ -718,12 +707,8 @@ def _check_r_max(cls, r_max: PositiveReal, cells: Cells) -> PositiveReal:

@classmethod
def _calculate_n_bins(
cls,
delta_r: PositiveReal,
r_max: PositiveReal,
r_min: PositiveReal
) -> Tuple[PositiveInt,
PositiveReal]:
cls, delta_r: PositiveReal, r_max: PositiveReal, r_min: PositiveReal
) -> Tuple[PositiveInt, PositiveReal]:
"""
Calculates the number of bins of the RDF analysis from the provided parameters.

Expand Down Expand Up @@ -783,10 +768,10 @@ def _infer_r_max(cls, cells: Cells) -> PositiveReal:
if not check_trajectory_pbc(cells):
cls.logger.error(
(
"To infer r_max of the RDF analysis, "
"the trajectory cannot be a vacuum trajectory. "
"Please specify r_max manually or use the "
"combination n_bins and delta_r."
"To infer r_max of the RDF analysis, "
"the trajectory cannot be a vacuum trajectory. "
"Please specify r_max manually or use the "
"combination n_bins and delta_r."
),
exception=RDFError
)
Expand Down Expand Up @@ -838,10 +823,7 @@ def _norm(

@classmethod
def _integration(
cls,
bins: Np1DNumberArray,
n_reference_indices: int,
n_frames: int
cls, bins: Np1DNumberArray, n_reference_indices: int, n_frames: int
) -> Np1DNumberArray:
"""
Calculates the integrated RDF analysis.
Expand Down
15 changes: 9 additions & 6 deletions PQAnalysis/analysis/rdf/rdf_input_file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,25 @@ def read(self):
super().read()
super().check_required_keys(self.required_keys)
super().check_known_keys(self.required_keys + self.optional_keys)
super().not_defined_optional_keys(self.optional_keys)

if (self.no_intra_molecular is not None and
(self.restart_file is None or self.moldescriptor_file is None)):
if (
self.no_intra_molecular is not None and
(self.restart_file is None or self.moldescriptor_file is None)
):
self.logger.error(
(
"The no_intra_molecular key can only be used "
"if both a restart file and a moldescriptor file are given."
"The no_intra_molecular key can only be used "
"if both a restart file and a moldescriptor file are given."
),
exception=InputFileError,
)

if self.moldescriptor_file is not None and self.restart_file is None:
self.logger.error(
(
"The moldescriptor_file key can only be "
"used in a meaningful way if a restart file is given."
"The moldescriptor_file key can only be "
"used in a meaningful way if a restart file is given."
),
exception=InputFileError,
)
Expand Down
2 changes: 1 addition & 1 deletion PQAnalysis/analysis/rdf/rdf_output_file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def write_before_run(self, rdf: RDF):
)
print(
" Target selection: ",
{rdf.target_selection},
rdf.target_selection,
file=self.file
)
print(
Expand Down
13 changes: 13 additions & 0 deletions PQAnalysis/atomic_system/atomic_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,17 @@ def __getitem__(
topology=self.topology[keys]
)

def __len__(self) -> int:
"""
Returns the number of atoms in the AtomicSystem.

Returns
-------
int
The number of atoms in the AtomicSystem.
"""
return self.n_atoms

def __str__(self) -> str:
"""
Returns the string representation of the AtomicSystem.
Expand All @@ -701,3 +712,5 @@ def __repr__(self) -> str:
The string representation of the AtomicSystem.
"""
return self.__str__()

__iter__ = None # To avoid iteration over the AtomicSystem object
Loading