-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster_analysis.py
More file actions
60 lines (47 loc) · 2.04 KB
/
cluster_analysis.py
File metadata and controls
60 lines (47 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import numpy as np
from ovito.io import import_file, export_file
from ovito.modifiers import ClusterAnalysisModifier, SelectTypeModifier, DeleteSelectedModifier
from ovito.vis import Viewport, OSPRayRenderer
def perform_cluster_analysis(input_file, particle_types, cutoff=3.0):
"""
Performs cluster analysis on a given input file for specific particle types.
:param input_file: Path to the input file containing particle data.
:param particle_types: Set of particle types to include in the analysis.
:param cutoff: Distance cutoff for cluster determination (default: 3.0).
"""
# Import file
pipeline = import_file(input_file)
pipeline.add_to_scene()
# Compute pipeline data
data = pipeline.compute()
# Apply SelectTypeModifier to select particles of specific types
pipeline.modifiers.append(SelectTypeModifier(
operate_on="particles",
property="Particle Type",
types=particle_types
))
# Apply DeleteSelectedModifier to remove selected particles
pipeline.modifiers.append(DeleteSelectedModifier())
# Apply ClusterAnalysisModifier for cluster analysis
pipeline.modifiers.append(ClusterAnalysisModifier(
cutoff=cutoff,
sort_by_size=True,
cluster_coloring=True
))
# Export results of the clustering algorithm to a text file
export_file(pipeline, 'clusters.txt', 'txt/table', key='clusters')
# Retrieve cluster information
data = pipeline.compute()
cluster_table = data.tables['clusters']
print("Cluster Size:")
print(cluster_table['Cluster Size'][...])
# Disable cell visualization
data.cell.vis.enabled = False
# Configure viewport and render image
vp = Viewport(type=Viewport.Type.Right)
vp.zoom_all()
vp.render_image(filename='simulation.png', size=(1000, 1000), renderer=OSPRayRenderer())
if __name__ == "__main__":
input_file = "/path/to/your/input/file.xyz"
particle_types = {'X'} # Set of particle types to exclude in the analysis
perform_cluster_analysis(input_file, particle_types)