예제 #1
0
 def test_userdefn_ValueErrors(self, universe):
     # Test len(gridcenter) != 3
     with pytest.raises(ValueError):
         D = density.density_from_Universe(
             universe,
             select=self.selections['static'],
             delta=self.delta,
             xdim=10.0,
             ydim=10.0,
             zdim=10.0,
             gridcenter=self.gridcenters['error1'])
     # Test gridcenter includes non-numeric strings
     with pytest.raises(ValueError):
         D = density.density_from_Universe(
             universe,
             select=self.selections['static'],
             delta=self.delta,
             xdim=10.0,
             ydim=10.0,
             zdim=10.0,
             gridcenter=self.gridcenters['error2'])
     # Test xdim != int or float
     with pytest.raises(ValueError):
         D = density.density_from_Universe(
             universe,
             select=self.selections['static'],
             delta=self.delta,
             xdim="MDAnalysis",
             ydim=10.0,
             zdim=10.0,
             gridcenter=self.gridcenters['static_defined'])
예제 #2
0
def test_gridcenter(u1):
    gridcenter = np.array([10, 10, 10])
    xdim = 190
    ydim = 200
    zdim = 210
    serial = density_from_Universe(u1,
                                   atomselection='name OD1',
                                   update_selection=True,
                                   gridcenter=gridcenter,
                                   xdim=xdim,
                                   ydim=ydim,
                                   zdim=zdim)
    parallel = DensityAnalysis(u1.atoms,
                               atomselection='name OD1',
                               updating=True,
                               gridcenter=gridcenter,
                               xdim=xdim,
                               ydim=ydim,
                               zdim=zdim)
    core_number = 4
    parallel.run(n_blocks=core_number, n_jobs=core_number)
    assert_almost_equal(serial.grid, parallel.density.grid)
    assert_almost_equal(parallel._gridcenter, gridcenter)
    assert len(parallel.density.edges[0]) == xdim + 1
    assert len(parallel.density.edges[1]) == ydim + 1
    assert len(parallel.density.edges[2]) == zdim + 1
예제 #3
0
def calcDensity(cutoff, **kwargs):
    """Retrive the density in Molar of density_sel"""

    for k, v in kwargs.items():
        exec(k + '=v')

    for co in cutoff:
        filenames = str(
            glob.glob(results_dir +
                      'structures/NAC_frames-{}-{}-{}-{}-*.gro'.format(
                          results_dir, prot, mol, c, co)))
        for f in filenames:
            xtc = f[:-4] + '.xtc'
            fit = f + '-fit.xtc'

            ref = mda.Universe(f)
            mobile = mda.Universe(f, xtc)
            alignment = align.AlignTraj(mobile, ref, filename=fit)
            alignment.run()

            fit_u = mda.Universe(filename + '.gro', fit)
            density = density_from_Universe(
                fit_u, delta=0.5
            )  #, atomselection=density_sel, update_selection=True)
            density.convert_density('Molar')
            density.export(filename + '-density_Molar.dx', type=double)
예제 #4
0
 def test_userdefn_boxshape(self, universe):
     D = density.density_from_Universe(
         universe,
         select=self.selections['static'],
         delta=1.0,
         xdim=8.0,
         ydim=12.0,
         zdim=17.0,
         gridcenter=self.gridcenters['static_defined'])
     assert D.grid.shape == (8, 12, 17)
예제 #5
0
 def test_userdefn_selwarning(self, universe):
     regex = ("Atom selection does not fit grid --- "
              "you may want to define a larger box")
     with pytest.warns(UserWarning, match=regex):
         D = density.density_from_Universe(
             universe,
             select=self.selections['static'],
             delta=self.delta,
             xdim=1.0,
             ydim=2.0,
             zdim=2.0,
             padding=0.0,
             gridcenter=self.gridcenters['static_defined'])
예제 #6
0
 def test_userdefn_padding(self, universe):
     regex = ("Box padding \(currently set at 1\.0\) is not used "
              "in user defined grids\.")
     with pytest.warns(UserWarning, match=regex):
         D = density.density_from_Universe(
             universe,
             select=self.selections['static'],
             delta=self.delta,
             xdim=100.0,
             ydim=100.0,
             zdim=100.0,
             padding=1.0,
             gridcenter=self.gridcenters['static_defined'])
예제 #7
0
def test_density_values(u1, n_blocks, stop, step):
    parallel = DensityAnalysis(u1.atoms,
                               atomselection='name OD1',
                               updating=True)
    parallel.run(n_blocks=n_blocks,
                 n_jobs=n_blocks,
                 start=0,
                 stop=stop,
                 step=step)
    serial = density_from_Universe(u1,
                                   atomselection='name OD1',
                                   update_selection=True,
                                   start=0,
                                   stop=stop,
                                   step=step)
    assert np.sum(serial.grid) == np.sum(parallel.density.grid)
    assert_almost_equal(serial.grid, parallel.density.grid, decimal=17)
예제 #8
0
    def check_density_from_Universe(self, atomselection, ref_meandensity,
                                    universe, tmpdir, **kwargs):
        with tmpdir.as_cwd():
            D = density.density_from_Universe(universe,
                                              select=atomselection,
                                              delta=self.delta,
                                              **kwargs)
            assert_almost_equal(D.grid.mean(),
                                ref_meandensity,
                                err_msg="mean density does not match")

            D.export(self.outfile)

            D2 = density.Density(self.outfile)
            assert_almost_equal(
                D.grid,
                D2.grid,
                decimal=self.precision,
                err_msg="DX export failed: different grid sizes")
예제 #9
0
    base + '5us_traj_popc_protein_lipid_popc.xtc',
    base + '15us_traj_protein_lipid_popc.xtc'
])

# define the contact condition in ångströms

contact_dist = 5
nearby = "name PO4 and (around " + str(
    contact_dist
) + " name SC1 or around " + str(contact_dist) + " name SC2 or around " + str(
    contact_dist) + " name SC3 or around " + str(contact_dist) + " name SC4)"

# write out 3D density of PO4 everywhere and near the protein in VTK Image Data

Dall = density_from_Universe(u,
                             delta=0.5,
                             atomselection="name PO4",
                             update_selection=True)
Dnear = density_from_Universe(u,
                              delta=1,
                              atomselection=nearby,
                              update_selection=True)

print('near:', Dnear.grid.shape)  # should be (60, 57, 51)
grid = tvtk.tvtk.ImageData(spacing=Dnear.delta,
                           origin=Dnear.origin,
                           dimensions=Dnear.grid.shape)
grid.point_data.scalars = Dnear.grid.ravel(order='F')
grid.point_data.scalars.name = 'POPC near SC1_4'
tvtk.write_data(
    grid, 'Dnear.vtk'
)  # omit `vtk` extension to write newer XML VTK, otherwise legacy VTK
예제 #10
0
 def test_has_DeprecationWarning(self, universe):
     with pytest.warns(DeprecationWarning,
                       match="will be removed in release 2.0.0"):
         D = density.density_from_Universe(universe,
                                           select=self.selections['static'],
                                           delta=self.delta)
예제 #11
0
import MDAnalysis as mda
from MDAnalysis.analysis.density import density_from_Universe
u = mda.Universe('GRO_file', 'XTC_FILE')

sto=len(u.trajectory)
for i in range(0,sto):
	x=i+1
	D=density_from_Universe(u, delta=1.0,start=i,stop=x,step=1, atomselection="name OH2",padding=0)
	D.convert_density('TIP3P') #assuming TIP3P
	D.export('water_density_convert_'+str(i)+'.dx')


	

예제 #12
0
import MDAnalysis as mda
from MDAnalysis.analysis.density import density_from_Universe
u = mda.Universe('../../step7_1.gro', '../../all_c_long.xtc')

sto = len(u.trajectory)
for i in range(0, sto):
    x = i + 1
    D = density_from_Universe(u,
                              delta=1.0,
                              start=i,
                              stop=x,
                              step=1,
                              atomselection="name OH2",
                              padding=0)
    P = density_from_Universe(u,
                              delta=1.0,
                              start=i,
                              stop=x,
                              step=1,
                              atomselection="protein",
                              padding=0)
    L = density_from_Universe(u,
                              delta=1.0,
                              start=i,
                              stop=x,
                              step=1,
                              atomselection="resname POPC",
                              padding=0)
    D.convert_density('TIP3P')  #assuming TIP3P
    D.export('water_density_convert_' + str(i) + '.dx')
    P.export('protein_density_notconvert_' + str(i) + '.dx')
예제 #13
0
#!/usr/bin/env python

from MDAnalysis import Universe
from MDAnalysis.analysis.density import density_from_Universe

uni = Universe("ref.gro", "./all_fit.xtc")
D = density_from_Universe(uni, delta=1.0, atomselection="name OW")
D.export("density.dx")