Example #1
0
def test_hdf5_simple():
    # This test does not write all possible outputs
    sys = get_system_water()
    ff = ForceField.generate(sys, pkg_resources.resource_filename(__name__, '../../data/test/parameters_water_bondharm.txt'))
    with h5.File('yaff.sampling.test.test_verlet.test_hdf5_simple.h5', driver='core', backing_store=False) as f:
        hdf5 = HDF5Writer(f)
        nve = VerletIntegrator(ff, 1.0*femtosecond, hooks=hdf5)
        nve.run(15)
        assert nve.counter == 15
        check_hdf5_common(hdf5.f, isolated=True)
        assert get_last_trajectory_row(f['trajectory']) == 16
        assert f['trajectory/counter'][15] == 15
Example #2
0
def test_hdf5_simple():
    # This test does not write all possible outputs
    sys = get_system_water()
    ff = ForceField.generate(sys, context.get_fn('test/parameters_water_bondharm.txt'))
    f = h5.File('yaff.sampling.test.test_verlet.test_hdf5_simple.h5', driver='core', backing_store=False)
    try:
        hdf5 = HDF5Writer(f)
        nve = VerletIntegrator(ff, 1.0*femtosecond, hooks=hdf5)
        nve.run(15)
        assert nve.counter == 15
        check_hdf5_common(hdf5.f, isolated=True)
        assert get_last_trajectory_row(f['trajectory']) == 16
        assert f['trajectory/counter'][15] == 15
    finally:
        f.close()
Example #3
0
def test_pair_pot_eidip_water_setdipoles():
    # '''Test if we can modify dipoles of PairPotEIDip object'''
    #Setup simple system
    system = get_system_water()
    rcut = 50.0*angstrom
    #Some arrays representing dipoles
    dipoles0 = np.array( [[1.0,2.0,3.0],[4.0,5.0,6.0],[7.0,8.0,9.0 ]] ) # natom x 3
    dipoles1 = np.array( [[9.0,8.0,7.0],[6.0,5.0,4.0],[3.0,2.0,1.0 ]] ) # natom x 3
    dipoles2 = np.array( [[9.0,8.0],[6.0,5.0],[3.0,2.0 ]] ) # natom x 2
    dipoles3 = np.array( [[9.0,8.0,7.0],[6.0,5.0,4.0]] ) # natom x 2
    #Array representing atomic polarizability tensors
    poltens_i = np.tile( np.diag([1.0,1.0,1.0]) , np.array([system.natom, 1]) )
    system.dipoles = dipoles0
    #Initialize pair potential
    pair_pot = PairPotEIDip(system.charges, system.dipoles, poltens_i, 0.0, rcut)
    #Check if dipoles are initialized correctly
    assert np.all( pair_pot.dipoles == dipoles0 )
    #Update the dipoles to new values
    system.dipoles[:] = dipoles1
    assert np.all( pair_pot.dipoles == dipoles1 )
    #Try to update dipoles of PairPot directly, this should raise an attribute error
    with assert_raises(AttributeError):
        pair_pot.dipoles = dipoles1
Example #4
0
def get_ff_water():
    system = get_system_water()
    fn_pars = context.get_fn('test/parameters_water.txt')
    return ForceField.generate(system, fn_pars)
Example #5
0
def get_ff_water():
    system = get_system_water()
    fn_pars = pkg_resources.resource_filename(
        __name__, '../../data/test/parameters_water.txt')
    return ForceField.generate(system, fn_pars)
Example #6
0
def get_ff_water():
    system = get_system_water()
    fn_pars = context.get_fn('test/parameters_water.txt')
    return ForceField.generate(system, fn_pars)
Example #7
0
def get_part_water_eidip(scalings = [0.5,1.0,1.0],rcut=14.0*angstrom,switch_width=0.0*angstrom, finite=False, alpha=0.0, do_radii=False):
    '''
    Make a system with one water molecule with a point dipole on every atom,
    setup a ForcePart...
    '''
    # Set dipoles
    dipoles = np.array( [[1.0,2.0,3.0],[4.0,5.0,6.0],[7.0,8.0,9.0 ]] ) # natom x 3
    # Initialize system, nlist and scaling
    system = get_system_water()
    #TODO make radii2 system attribute
    system.radii = np.array( [ 1.5,1.2,1.2] ) * angstrom
    system.radii2 = np.array( [1.6,1.3,1.2] ) * angstrom
    if finite:
        #Make a system with point dipoles approximated by two charges
        system = make_system_finite_dipoles(system, dipoles, eps=0.0001*angstrom)
    if not do_radii:
        system.radii *= 0.0
        if not finite:system.radii2 *= 0.0
    nlist = NeighborList(system)
    scalings = Scalings(system, scalings[0], scalings[1], scalings[2])
    # Set poltens
    poltens_i = np.tile( 0.0*np.diag([1.0,1.0,1.0]) , np.array([system.natom, 1]) )
    # Create the pair_pot and part_pair
    if finite:
        pair_pot = PairPotEI(system.charges,alpha, rcut, tr=Switch3(switch_width), radii=system.radii)
    else:
        pair_pot = PairPotEIDip(system.charges, dipoles, poltens_i, alpha, rcut, tr=Switch3(switch_width), radii=system.radii, radii2=system.radii2)
    part_pair = ForcePartPair(system, nlist, scalings, pair_pot)
    nlist.update()
    #Make a different nlist in case we approximate the point dipoles with charges
    #Interactions between charges at the same site should be excluded
    if finite:
        neigh_dtype = [
        ('a', int), ('b', int), ('d', float),        # a & b are atom indexes, d is the distance
        ('dx', float), ('dy', float), ('dz', float), # relative vector (includes cell vectors of image cell)
        ('r0', int), ('r1', int), ('r2', int)        # position of image cell.
            ]
        nneigh = np.sum( nlist.neighs[0:nlist.nneigh]['d'] > 0.2*angstrom )
        new_neighs = np.zeros(nneigh, dtype=neigh_dtype)
        counter = 0
        for n in nlist.neighs[0:nlist.nneigh]:
            if n['d']>0.2*angstrom:
                new_neighs[counter] = n
                counter += 1
        nlist.neighs = new_neighs
        nlist.nneigh = nneigh
    # The pair function
    def pair_fn(i, j, d, delta):
        energy = 0.0
        #Charge-Charge
        energy += system.charges[i]*system.charges[j]/d
        if not finite:
            #Charge-Dipole
            energy += system.charges[i]*np.dot(delta, pair_pot.dipoles[j,:])/d**3
            #Dipole-Charge
            energy -= system.charges[j]*np.dot(delta, pair_pot.dipoles[i,:])/d**3
            #Dipole-Dipole
            energy += np.dot( pair_pot.dipoles[i,:] , pair_pot.dipoles[j,:] )/d**3 - \
                             3*np.dot(pair_pot.dipoles[i,:],delta)*np.dot(delta,pair_pot.dipoles[j,:])/d**5
        if d > rcut - switch_width:
            x = (rcut - d)/switch_width
            energy *= (3-2*x)*x*x
        return energy
    return system, nlist, scalings, part_pair, pair_pot, pair_fn
Example #8
0
def get_ff_water():
    system = get_system_water()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_water.txt')
    return ForceField.generate(system, fn_pars)