-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatomic_strain.py
More file actions
56 lines (46 loc) · 1.65 KB
/
atomic_strain.py
File metadata and controls
56 lines (46 loc) · 1.65 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
import numpy as np
from ovito.io import import_file
from ovito.modifiers import AtomicStrainModifier, SelectTypeModifier, DeleteSelectedModifier, ColorCodingModifier
from ovito.vis import Viewport, OSPRayRenderer
def calculate_atomic_strain(input_file):
"""
Calculates the atomic strain of a system and saves an image of the simulation.
Args:
input_file (str): Path to the input XYZ file.
Returns:
None
"""
# Import file
pipeline = import_file(input_file)
pipeline.add_to_scene()
data = pipeline.compute()
# Select all particles we don't want to study
pipeline.modifiers.append(SelectTypeModifier(
operate_on="particles",
property="Particle Type",
types={'Atoms to delete'}
))
# Delete selected particles
pipeline.modifiers.append(DeleteSelectedModifier())
# Calculate atomic strain
pipeline.modifiers.append(AtomicStrainModifier(
cutoff=3.0
))
# Color code based on shear strain
pipeline.modifiers.append(ColorCodingModifier(
operate_on="particles",
property='Shear Strain',
gradient=ColorCodingModifier.Rainbow()
))
data.cell.vis.enabled = False # Disable cell visualization
# Render and save an image of the simulation
vp = Viewport(type=Viewport.Type.Front)
vp.zoom_all()
vp.render_image(filename='simulation.png',
size=(1000, 1000),
renderer=OSPRayRenderer())
print("The simulation has been saved as 'simulation.png'.")
if __name__ == "__main__":
# Example usage
input_file = input("Enter the path to the file: ")
calculate_atomic_strain(input_file)