amepproject / amep

The Active Matter Evaluation Package (AMEP) - a Python library for the analysis of particle-based and continuum simulation data of soft and active matter systems
https://amepproject.de/
GNU General Public License v3.0
12 stars 2 forks source link

BUG: evaluate.ClusterGrowthRate incorrect computation for fields #69

Open kay-ro opened 1 month ago

kay-ro commented 1 month ago

Description:

If evaluate.ClusterGrowthRate is run with a field trajectory, the method pbc.kdtree() is executed. The calculation in kdtree is then incorrect because the coordinates of the right box end are shifted to the left box start (because kdtree needs r in [0,L). )

        # shift particles at the right border to the left border
        # to avoid errors occuring if a particle is placed at L_i
        coords[coords[:,0]==box[0],0]=0
        coords[coords[:,1]==box[1],1]=0
        coords[coords[:,2]==box[2],2]=0
        # should not be done for fields! all right boundaries will
        # be shifted to the left and would be double-occupied!

Code for reproduction:

# branch gromacs_reader
python -m unittest test_evaluate.py

Error message:

if the three lines from above are not executed (which are usually no problem for particle-based simulations), the error is:

...
======================================================================
ERROR: test_cluster_growth (test_evaluate.TestEvaluateMethods)
Test the cluster growth methods.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dormann/Documents/git_amep/test/test_evaluate.py", line 59, in test_cluster_growth
    self.assertTrue((ClusterGrowth(self.field_traj, scale=1.5,
  File "/home/dormann/Documents/git_amep/amep/evaluate.py", line 3752, in __init__
    self.__frames, self.__avg, self.__indices = average_func(
  File "/home/dormann/Documents/git_amep/amep/utils.py", line 142, in average_func
    func_result = [func(x, **kwargs) for x in tqdm(data[evaluated_indices])]
  File "/home/dormann/Documents/git_amep/amep/utils.py", line 142, in <listcomp>
    func_result = [func(x, **kwargs) for x in tqdm(data[evaluated_indices])]
  File "/home/dormann/Documents/git_amep/amep/evaluate.py", line 3835, in __compute_fields
    sizes, _, _, _, _, _, _ = cluster_properties(
  File "/home/dormann/Documents/git_amep/amep/continuum.py", line 804, in cluster_properties
    dist = distance_matrix(
  File "/home/dormann/Documents/git_amep/amep/pbc.py", line 1186, in distance_matrix
    ctree = kdtree(coords, box_boundary, pbc = pbc)
  File "/home/dormann/Documents/git_amep/amep/pbc.py", line 674, in kdtree
    return KDTree(coords, boxsize=box)
  File "/home/dormann/anaconda3/envs/anc310/lib/python3.10/site-packages/scipy/spatial/_kdtree.py", line 360, in __init__
    super().__init__(data, leafsize, compact_nodes, copy_data,
  File "_ckdtree.pyx", line 584, in scipy.spatial._ckdtree.cKDTree.__init__
ValueError: Some input data are greater than the size of the periodic box.

----------------------------------------------------------------------
Ran 1 test in 0.019s

FAILED (errors=1)

Python and AMEP versions:

1.0.2

Additional information:

either the execution of kdtree for field must be stopped or the box_boundary must be larger than the field maximum and minimum locations.

How did you install AMEP?

None