def test_serial():
    universe = mda.Universe(waterPSF, waterDCD)
    sel_string = 'all'
    selection = universe.select_atoms(sel_string)

    xpos = np.array([0., 0., 0., 0.0072334, 0.00473299, 0., 0., 0., 0., 0.])
    ld = LinearDensity(selection, binsize=5).run()
    assert_almost_equal(xpos, ld.results['x']['pos'])
예제 #2
0
def density(u, binsize, block):
    '''Computes water density profile perpendicular to a surface.

    Args:
        u: MDAnalysis Universe object containing trajectory.
        binsize: Bin size of profile (histogram).
        block: Range of frames composing block.

    Returns:
        Linear density profile.
    '''

    # Select water
    water = u.select_atoms('name O or name H')

    # Initialize and run linear density analysis
    ldens = LinearDensity(water, binsize=binsize, verbose=True)
    ldens.run(start=block.start, stop=block.stop)

    return ldens.results.z.pos
예제 #3
0
 def test_serial(self):
     ld = LinearDensity(self.selection, binsize=5).run()
     assert_allclose(self.xpos, ld.results['x']['pos'], rtol=1e-6, atol=0)
예제 #4
0
    def electron_density_mdanalysis(self):
        '''This function calulate the charge density through MDAnalaysis'''

        u = mda.Universe(self.tprpath, self.trjpath)

        lipid_types_first = ''.join(self.molecules[0])
        print(lipid_types_first)
        self.lipid_type_items = ' '.join(self.molecules)

        print(lipid_types_first)

        selection = u.select_atoms('resname {}'.format(self.lipid_type_items))

        ref_selection = u.select_atoms(
            'resname {} and name P'.format(lipid_types_first))

        print(self.times[2])

        interval_of_frames = str(self.times[2])
        print(interval_of_frames)

        if self.times[2] == '1000':
            start_frame = 100
            frame_intervals = 1
            end_frame = 300
        else:
            start_frame = 1000
            frame_intervals = 10
            end_frame = 3000

        Idens = LinearDensity(selection,
                              grouping='atoms',
                              binsize=0.25,
                              start=start_frame,
                              step=frame_intervals,
                              stop=end_frame)
        Idens.run()
        Idens.save(description='densprof', form='txt')

        # subtracting the center of geometry of the lipid from the first column of the data
        # calculating center of geometry of lipids

        u = self.universe
        cog = []
        for i_ts, ts in enumerate(u.trajectory[start_frame::frame_intervals]):

            ref_selection_xyz = ref_selection.center_of_geometry()
            cog.append(ref_selection_xyz[2])

        centerofgeometry_z = np.mean(cog)
        ####

        dat = np.loadtxt('{}_{}.densprof_atoms.ldens'.format(self.system,
                                                             self.temperature,
                                                             skiprows=2))
        dat[:, 0] = dat[:, 0] - centerofgeometry_z
        np.savetxt('{}_{}.densprof_atoms_centered.ldens'.format(
            self.system, self.temperature),
                   dat,
                   delimiter=' ',
                   fmt='%.5f')
def test_results_warning():
    universe = mda.Universe(waterPSF, waterDCD)
    msg = ("The structure of the `results` dictionary will change in "
            "MDAnalysis version 2.0.")
    with pytest.warns(DeprecationWarning, match=msg):
        LinearDensity(universe.atoms).run()