示例#1
0
 def testCenterOfMass(self):
     """ Tests the center-of-mass calculator """
     almost_equal = np.testing.assert_array_almost_equal
     # Make some systems we know the answer for
     array = np.asarray([[1, 0, 0], [-1, 0, 0]])
     masses = np.asarray([1, 1])
     self.assertTrue(np.all(geo.center_of_mass(array, masses) == 0))
     # Change masses
     masses = np.asarray([2, 1])
     almost_equal(geo.center_of_mass(array, masses), np.array([1/3, 0, 0]))
示例#2
0
文件: offlib.py 项目: drroe/ParmEd
def _imaging_atom(res):
    """
    Determines the imaging atom for the residue. If all atoms are hydrogen
    except 1, it is the heavy atom. Otherwise, it is the atom *closest* to the
    COM of the residue
    """
    from parmed.geometry import center_of_mass
    #TODO implement the docstring
    found_heavy = False
    heavy_idx = -1
    for i, atom in enumerate(res):
        if atom.atomic_number > 1:
            heavy_idx = i
            if found_heavy: break
            found_heavy = True
    else:
        if heavy_idx != -1:
            return heavy_idx
        return 0 # No heavy atoms?? No imaging atom, then.
    # Now pick the atom closest to COM (if numpy is available)
    if np is None:
        warnings.warn('numpy not available. imaging atom set to 0')
        return 0
    coords = res.coordinates.reshape((len(res), 3))
    masses = np.zeros(len(res))
    for i, atom in enumerate(res):
        if atom.mass == 0:
            masses[i] = pt.Mass[pt.Element[atom.atomic_number]]
        else:
            masses[i] = atom.mass
    com = center_of_mass(coords, masses)
    diff = coords - com
    return np.argmin((diff * diff).sum(axis=1)) + 1
示例#3
0
文件: offlib.py 项目: xy21hb/ParmEd
def _imaging_atom(res):
    """
    Determines the imaging atom for the residue. If all atoms are hydrogen
    except 1, it is the heavy atom. Otherwise, it is the atom *closest* to the
    COM of the residue
    """
    from parmed.geometry import center_of_mass
    #TODO implement the docstring
    found_heavy = False
    heavy_idx = -1
    for i, atom in enumerate(res):
        if atom.atomic_number > 1:
            heavy_idx = i
            if found_heavy: break
            found_heavy = True
    else:
        if heavy_idx != -1:
            return heavy_idx
        return 0 # No heavy atoms?? No imaging atom, then.
    coords = res.coordinates.reshape((len(res), 3))
    masses = np.zeros(len(res))
    for i, atom in enumerate(res):
        if atom.mass == 0:
            masses[i] = pt.Mass[pt.Element[atom.atomic_number]]
        else:
            masses[i] = atom.mass
    com = center_of_mass(coords, masses)
    diff = coords - com
    return np.argmin((diff * diff).sum(axis=1))