royallgroup / TCC

The Topological Cluster Classification algorithm
https://royallgroup.github.io/TCC/
GNU General Public License v3.0
12 stars 5 forks source link

improve the Python wrapper #135

Closed yangyushi closed 3 years ago

yangyushi commented 3 years ago

I made several improvements

  1. correctly implemented multiple frame analysis (again). The previous issue is that the output mode is 'w' so only the last frame will be analysed.
  2. If the number of analyse frame is given by the user, then the user input have a higher priority
  3. I re-implemented the function to get particle-level information of the TCC clusters.

The minimum example to access the new function is,

import numpy as np
from tcc_python_scripts.tcc import wrapper

coords = np.random.random((25, 1000, 3))
box = [1, 1, 1]

tcc = wrapper.TCCWrapper()
# only the first 10 out of 25 frames will be analysed
tcc.input_parameters['Run']['frames'] = 10
tcc.input_parameters['Output']['Raw'] = True
tcc.input_parameters['Simulation']['rcutAA'] = 0.2
tcc.clusters_to_analyse = ['sp5a', 'sp4a', 'sp3a']
tcc.run(box, coords)

# print first frame of sp5a, particles 1 - 5
cluster_dict = tcc.get_cluster_dict(tcc.clusters_to_analyse)
print("sp5a in the 1st frame: \n", cluster_dict['sp5a'][0][:5].T)

# print all clusters in the first frame
print("\nAll cluster in the 1st frame")
tables = tcc.get_cluster_table(tcc.clusters_to_analyse)
print(tables[0].head())

with the following result,

sp5a in the 1st frame: 
 [[ True  True False  True  True]]

All cluster in the 1st frame
    sp5a  sp4a   sp3a
0   True  True  False
1   True  True   True
2  False  True  False
3   True  True   True
4   True  True   True
yangyushi commented 3 years ago

I will improve the doc of the code and find a way to update the pull request later (I don't know how to do it now)

tranqui commented 3 years ago

The pull request is in the devel branch, so you should be able to just push your commits there to update the pull request automatically.