Hello Community Readers,
I was testing out how to call ovito from a running lammps simulation using the “ovito.io.lammps” in ovito and “fix python” functionality in lammps. I have a custom python function to compute the FCC fraction at certain timesteps. But it runs into an Attribute not found error. It refers to the attribute “rank”. I checked to see if the lammps simulation state was correctly imported in the prior step and it was being imported fine.
The details of the code and error are provided below. If anyone can shed some light on how I go forward from here, it will be really helpful.
Python Function
from lammps import lammps
from ovito.io.lammps import lammps_to_ovito
from ovito.modifiers import PolyhedralTemplateMatchingModifier
def compute_fcc_fraction(lammps_ptr):
lmp = lammps(ptr=lammps_ptr) # Access the LAMMPS simulation state
data = lammps_to_ovito(lmp) # Convert to OVITO data representation
# Skip analysis on non-master MPI ranks
if data is None:
return
# Apply the Polyhedral Template Matching modifier
ptm = PolyhedralTemplateMatchingModifier(rmsd_cutoff=0.155)
data.apply(ptm)
# Calculate FCC fraction
fcc_count = data.attributes['PolyhedralTemplateMatching.counts.FCC']
total_atoms = data.particles.count
fcc_fraction = fcc_count / total_atoms
# Save the result to a file
timestep = int(lmp.get_thermo('step'))
with open('fcc_fraction.txt', 'a') as f: # Append to the file
f.write(f'{timestep} {fcc_fraction:.2f}\n')
Lammps fix python part
python source fcc_fraction.py
fix fcc_analysis all python/invoke 1 end_of_step compute_fcc_fraction
Error
Traceback (most recent call last):
File “fcc_fraction.py”, line 8, in compute_fcc_fraction
data = lammps_to_ovito(lmp) # Convert to OVITO data representation
^^^^^^^^^^^^^^^^^^^^
File “/work/07691/aswamy96/miniconda/envs/lammps-python/lib/python3.11/site-packages/ovito/io/lammps/init.py”, line 91, in lammps_to_ovito
if lmp.get_mpi_comm().rank != 0:
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: ‘NoneType’ object has no attribute ‘rank’
ERROR: Fix python/invoke end_of_step() method failed (…/fix_python_invoke.cpp:100)
Last command: run 1