Tutorial: Contact Angle Analysis (Sliced Method)
This tutorial explains how to compute the contact angle of a droplet using the sliced method in wetting_angle_kit.
1. Overview
The sliced method divides the droplet into slices (along the z-axis) and fits a geometric model (e.g. spherical) to the liquid–solid interface profile. This is ideal for study the evolution of the angles among a trajectory.
2. Requirements
Before running the example, ensure you have installed:
pip install wetting_angle_kit ase numpy
Example trajectory:
tests/trajectories/traj_spherical_drop_4k.lammpstrj
3. Example Code
# Import necessary modules
from wetting_angle_kit.parser import DumpParser, DumpWaterMoleculeFinder
from wetting_angle_kit.contact_angle_method import contact_angle_analyzer
# --- Step 1: Define the trajectory file ---
filename = "../../tests/trajectories/traj_spherical_drop_4k.lammpstrj"
# --- Step 2: Initialize the water molecule finder ---
wat_find = DumpWaterMoleculeFinder(
filename,
particle_type_wall={3}, # Wall particle types
oxygen_type=1, # Oxygen atom type
hydrogen_type=2,
) # Hydrogen atom type
# --- Step 3: Identify oxygen atom indices ---
oxygen_indices = wat_find.get_water_oxygen_ids(frame_index=0)
print("Number of water molecules:", len(oxygen_indices))
# --- Step 4: Initialize the parser ---
parser = DumpParser(filename)
# --- Step 5: Create the contact angle analyzer ---
# Using the 'sliced' method with a spherical model
analyzer = contact_angle_analyzer(
method="sliced",
parser=parser,
output_dir="result_dump_spherical_sliced",
atom_indices=oxygen_indices,
droplet_geometry="spherical", # Geometry fitting model
delta_gamma=20, # Smoothing parameter
)
# --- Step 6: Run the analysis ---
results = analyzer.analyze([1]) # Analyze frame 1
# --- Step 7: Display results ---
print("Analysis results:", results)
4. Expected Output
After running the example, you’ll see something like:
Number of water molecules: 423
Analysis results: {'frame': 1, 'contact_angle': 104.7, 'fit_quality': 0.96}
If plotting is enabled, a visualization of the droplet profile and the fitted spherical interface is generated in result_dump_spherical_sliced/.
5. Tips
Use
droplet_geometry='spherical'for droplets anddroplet_geometry='cylinder_y'for cylindrical droplet on the y axis or'cylinder_x'for cylinder on the x axis.Adjust
delta_gammafor smoother or sharper slicing (larger = smoother).To analyze multiple frames:
results = analyzer.analyze(range(0, 50, 10))
Output files include raw interface data and optional plots (if enabled).