-1

Hello I am learning MDAnalysis through python-3.7. Would you please check my code and advise how to resolve the following error:

Traceback (most recent call last):
  File "/home/pulokdeb/projects/def-sohrabz/pulokdeb/beluga_python/Closest_atom_Oxy_group.py", line 242, in <module>
    eigen_value = iio.eigen_vals()
  File "/home/pulokdeb/ENV/lib/python3.7/site-packages/MDAnalysis/core/topologyattrs.py", line 1347, in eigen_vals
    com = atomgroup.center_of_mass(pbc=pbc)

NameError: name 'pbc' is not defined

The code (partial) is below:

def radius_of_gyration(group, pbc=False, **kwargs):
    """Radius of gyration.

    Parameters
    ----------
    pbc : bool, optional
        If ``True``, move all atoms within the primary unit cell before
        calculation. [``False``]


    .. versionchanged:: 0.8 Added *pbc* keyword

    """
    atomgroup = group.atoms
    masses = atomgroup.masses

    com = atomgroup.center_of_mass(pbc=pbc)
    if pbc:
        recenteredpos = atomgroup.pack_into_box(inplace=False) - com
    else:
        recenteredpos = atomgroup.positions - com

    rog_sq = np.sum(masses * np.sum(recenteredpos**2,
                                    axis=1)) / atomgroup.total_mass()

    return np.sqrt(rog_sq)

transplants[GroupBase].append(
    ('radius_of_gyration', radius_of_gyration))
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • In the discussion on the mdnalysis-discussion mailing list https://groups.google.com/g/mdnalysis-discussion/c/CyTFEHEX2cs we already determined that the problem is with a customized version of MDAnalysis. If anyone wants to attempt to solve Pulok's problem I suggest they also look at the mailinglist thread. (Also https://groups.google.com/g/mdnalysis-discussion/c/HwZDg6FfqMQ/m/RANgRLL8AgAJ). – orbeckst Oct 19 '20 at 19:42

1 Answers1

0

I changed a few lines (def_eif_vals) in topologyattrs.py file and got my results. Hope it works for my future simulations.

def shape_parameter(group, pbc=False, **kwargs): """Shape parameter.

    See [Dima2004a]_ for background information.

    Parameters
    ----------
    pbc : bool, optional
        If ``True``, move all atoms within the primary unit cell before
        calculation. [``False``]


    References
    ----------
    .. [Dima2004a] Dima, R. I., & Thirumalai, D. (2004). Asymmetry
       in the shapes of folded and denatured states of
       proteins. *J Phys Chem B*, 108(21),
       6564-6570. doi:`10.1021/jp037128y
       <https://doi.org/10.1021/jp037128y>`_


    .. versionadded:: 0.7.7
    .. versionchanged:: 0.8 Added *pbc* keyword

    """
    atomgroup = group.atoms
    masses = atomgroup.masses

    com = atomgroup.center_of_mass(pbc=pbc)
    if pbc:
        recenteredpos = atomgroup.pack_into_box(inplace=False) - com
    else:
        recenteredpos = atomgroup.positions - com
    tensor = np.zeros((3, 3))

    for x in range(recenteredpos.shape[0]):
        tensor += masses[x] * np.outer(recenteredpos[x, :],
                                       recenteredpos[x, :])
    tensor /= atomgroup.total_mass()
    eig_vals = np.linalg.eigvalsh(tensor)
    shape = 27.0 * np.prod(eig_vals - np.mean(eig_vals)
                           ) / np.power(np.sum(eig_vals), 3)

    return shape

transplants[GroupBase].append(
    ('shape_parameter', shape_parameter))

def eigen_vals(group, pbc=False, **kwargs):
    """ Changed by Pulok Deb
    """
    atomgroup = group.atoms
    masses = atomgroup.masses

    com = atomgroup.center_of_mass(pbc=pbc)
    if pbc:
        recenteredpos = atomgroup.pack_into_box(inplace=False) - com
    else:
        recenteredpos = atomgroup.positions - com
    tensor = np.zeros((3, 3))

    for x in range(recenteredpos.shape[0]):
        tensor += masses[x] * np.outer(recenteredpos[x, :],
                                       recenteredpos[x, :])
    tensor /= atomgroup.total_mass()
    eig_vals = np.linalg.eigvalsh(tensor)


    return eig_vals

transplants[GroupBase].append(
    ('eigen_vals', eigen_vals))

@warn_if_not_unique
@check_pbc_and_unwrap