…
I know that usually you would put a lammps file like this: pipeline = import_file(f"mgel.dump.0"), but I was wondering if I could also put positions there since I have many molecules (microgels) in my box and I want the volume of each molecule/microgel while properly taking care of the boundary conditions.
Thank you very much for your fast reply! I get an error: Traceback (most recent call last):
File “ratio_volumina.py”, line 14, in
from ovito.pipeline import Pipeline, PythonSource
ImportError: cannot import name ‘PythonSource’ from ‘ovito.pipeline’ (/home/emanuela/.local/lib/python3.8/site-packages/ovito/pipeline/init.py) is my python to old?
Thank you very much for your fast reply! I get an error: Traceback (most recent call last):
File “ratio_volumina.py”, line 14, in
from ovito.pipeline import Pipeline, PythonSource
ImportError: cannot import name ‘PythonSource’ from ‘ovito.pipeline’ (/home/emanuela/.local/lib/python3.8/site-packages/ovito/pipeline/init .py) is my python to old?
I managed to fix my problem by using a temporary file:
def calculate_surface_mesh_volume(positions):
“”"
Saves positions to a temporary file and computes the surface mesh volume.
“”"
with tempfile.NamedTemporaryFile(suffix=“.xyz”, delete=False) as tmp:
# Write positions in XYZ format
tmp.write(f"{len(positions)}\n\n".encode()) # XYZ file header
for pos in positions:
tmp.write(f"Particle {pos[0]} {pos[1]} {pos[2]}\n".encode())
tmp_filename = tmp.name
# Load the temporary file into OVITO
pipeline = import_file(tmp_filename)
# Apply the ConstructSurfaceModifier to compute the surface mesh
probe_radius = 7.0
pipeline.modifiers.append(ConstructSurfaceModifier(
method=ConstructSurfaceModifier.Method.AlphaShape,
radius=probe_radius,
identify_regions=True
))
data = pipeline.compute()
# Retrieve the filled volume attribute
shell_volume = data.attributes['ConstructSurfaceMesh.filled_volume']
# Clean up temporary file
os.remove(tmp_filename)
return shell_volume