Forum Navigation
You need to log in to create posts and topics.

Regarding the calculation of Mean square displacement

I have been trying to calculate the Mean square displacement using the Python script

def modify(frame, data):
    # Access the per-particle displacement magnitudes computed by the
    # CalculateDisplacementsModifier that precedes this user-defined modifier in the
    # data pipeline:
    displacement_magnitudes = data.particles['Displacement Magnitude']

    # Compute MSD:
    msd = numpy.sum(displacement_magnitudes ** 2) / len(displacement_magnitudes)

    # Output MSD value as a global attribute:
    data.attributes["MSD"] = msd

as given in the Manual



but the system shows the following error

The Python script has exited with an error.

Traceback (most recent call last):

File "<string>", line 11, in modify

NameError: name 'numpy' is not defined


What should i do ????


Please add the statement import numpy to the top of the script. It got cut off in the documentation and is required, because the modifier function calls the sum() function from the NumPy Python module.