def test_constraint(): box = Box() assert (box.is_inside([0.5, 0.5, 0.5])) assert (not box.is_inside([0.5, 0.5, 1.5])) assert (not box.is_inside([0.5, 1.5, 0.5])) assert (not box.is_inside([1.5, 0.5, 0.5]))
def test_constraint(): box = Box() assert (box.is_inside([0.5,0.5,0.5])) assert ( not box.is_inside([0.5,0.5,1.5])) assert ( not box.is_inside([0.5,1.5,0.5])) assert ( not box.is_inside([1.5,0.5,0.5]))
def test_constrain_box_on_polymer(): box = Box([0, 0, 0], [10, 10, 10]) coords, bonds, type_beads, ids = one_polymer(N=200, type_bead=1, ptolerance=0, type_polymer="linear", start_id=0, gconstrain=[box]) for p in coords: assert (box.is_inside(p))
def test_lammps_angle(): Simu = LSimu() box = Box([0,0,0],[10,10,10]) liaison = {"1-1":[1,1]} angle_def = {"1-1-1":[20,1]} P1 = Polymer(N=20,type_bead=1,liaison=liaison,angle_bond=True,angle_def=angle_def,ptolerance=0,type_polymer="linear",start_id=0,lconstrain=[],gconstrain=[box]) Simu.add(P1) Simu.add_box(box) for idl,value in liaison.iteritems(): R0,idbond = value idpair1,idpair2=map(int,idl.split("-")) Simu.add_bond(typeb="harmonic",idbond=idbond,K=80,R0=R0) Simu.add_pair(typep="lj/cut",idpair1=idpair1,idpair2=idpair2,epsilon=1,sigma=R0,cutoff1=1.15) for idl,value in angle_def.iteritems(): K,idangle = value idpair1,idpair2,idpair3=map(int,idl.split("-")) Simu.add_angle(typea="harmonic",idangle=idangle,K=K,theta=180) Simu.generate_xyz("test/lp.xyz",Mass="one") Simu.generate_interactions("test/ainteractions") Simu.generate_pdb("test/lp.pdb") Simu.generate_script("test/lp.txt",run_length=10000,samplingrate=10,initconf="test/lp.xyz", outtraj="test/lp.dcd",outfile="test/lp.xyz",interactions="test/ainteractions",particle="1 2") Simu.run(script="test/lp.txt")
def test_generate_interaction(): Simu = LSimu() Simu.create_polymers(NP=10,N=100,box=Box([0,0,0],[10,10,10])) Simu.add_bond(typeb="harmonic",idbond=1,K=80,R0=1) Simu.add_pair(typep="lj/cut",idpair1=1,idpair2=1,epsilon=1,sigma=1,cutoff1=1.12) Simu.generate_interactions("test/interaction")
def test_constrain_on_polymer_start(): start = Point(index=0, position=[0.2, 0.2, 0.2]) #end = Point(index=199,position=[0.2,0.2,0.2]) box = Box([0, 0, 0], [10, 10, 10]) coords, bonds, type_beads, ids = one_polymer(N=20, type_bead=1, ptolerance=0, type_polymer="linear", start_id=0, lconstrain=[start], gconstrain=[box]) assert (norm(coords[0] - np.array([0.2, 0.2, 0.2])) < 0.01)
def test_constrain_on_polymer_end(): end = Point(index=19, position=[0.2, 0.2, 0.2]) #end = Point(index=199,position=[0.2,0.2,0.2]) box = Box([0, 0, 0], [20, 20, 20]) coords, bonds, type_beads, ids = one_polymer(N=20, type_bead=1, ptolerance=0, type_polymer="linear", start_id=0, lconstrain=[end], gconstrain=[box], max_trial=1000) print norm(coords[-2] - np.array([0.2, 0.2, 0.2])) assert (norm(coords[-2] - np.array([0.2, 0.2, 0.2])) < 3)
def test_lammps_from_hand_mix_interactions(): Simu = LSimu() box = Box([0,0,0],[10,10,10]) liaison = {"1-1":[1,1],"1-2":[1,2],"2-2":[1,3]} P1 = Polymer(N=20,type_bead=[1]*10+[2]*10,liaison=liaison,ptolerance=0,type_polymer="linear",start_id=0,lconstrain=[],gconstrain=[box]) Simu.add(P1) Simu.add_box(box) for idl,value in liaison.iteritems(): R0,idbond = value idpair1,idpair2=map(int,idl.split("-")) Simu.add_bond(typeb="harmonic",idbond=idbond,K=350,R0=R0) Simu.add_pair(typep="lj/cut",idpair1=idpair1,idpair2=idpair2,epsilon=1,sigma=R0,cutoff1=1.15) Simu.generate_xyz("test/mix.xyz",Mass="one") Simu.generate_interactions("test/softinteractions") Simu.generate_pdb("test/mix.pdb") Simu.generate_script("test/basic.txt",run_length=10000,samplingrate=100,initconf="test/mix.xyz",outtraj="test/out.dcd", outfile="test/final.xyz",interactions="test/softinteractions",particle="1 2") Simu.run(script="test/basic.txt") box = Box([0,0,0],[10,10,10]) Simu.add_box(box) Simu.clean_interactions() for idl,value in liaison.iteritems(): R0,idbond = value idpair1,idpair2=map(int,idl.split("-")) Simu.add_bond(typeb="fene",idbond=idbond,K=80,R0=R0,epsilon=1.2,sigma=1) Simu.add_pair(typep="lj/cut",idpair1=idpair1,idpair2=idpair2,epsilon=1,sigma=R0,cutoff1=1.15) Simu.generate_xyz("test/mix2.xyz",Mass="one",from_lammps_xyz="test/final.xyz") Simu.generate_interactions("test/interactions") Simu.generate_script("test/basic_rest.txt",template_name="./template/basic.txt", run_length=1000,samplingrate=10,initconf="test/mix2.xyz",outtraj="test/out2.dcd",outfile="test/out2.xyz", interactions="test/interactions",particle="1 2") Simu.run(script="test/basic_rest.txt")
def test_lammps_from_hand(): Simu = LSimu() box = Box([0,0,0],[10,10,10]) P1 = Polymer(N=20,type_bead=1,ptolerance=0,type_polymer="linear",start_id=0,lconstrain=[],gconstrain=[box]) Simu.add(P1) Simu.add_box(box) Simu.add_bond(typeb="harmonic",idbond=1,K=80,R0=1) Simu.add_pair(typep="lj/cut",idpair1=1,idpair2=1,epsilon=1,sigma=1,cutoff1=1.12) Simu.generate_xyz("test/mixh.xyz",Mass="one") Simu.generate_interactions("test/interactionsh") Simu.generate_pdb("test/mixh.pdb") Simu.generate_script("test/basich.txt",run_length=1000,samplingrate=10,initconf="test/mixh.xyz", outtraj="test/out.dcd",outfile="test/out.xyz",interactions="test/interactionsh",particle="1") Simu.run(script="test/basich.txt")
def test_bond_size(): box = Box([-100, -100, -100], [400, 400, 400]) coords, bonds, type_beads, ids = one_polymer(N=400, type_bead=1, liaison={"1-1": [2.0, 1]}, ptolerance=0, type_polymer="linear", start_id=0, lconstrain=[], gconstrain=[box], max_trial=300000, rc=0.5, virtual_lp=None, rigid_constrain=True) bonds = np.mean(np.sqrt(np.sum((coords[1:] - coords[:-1])**2, axis=1))) assert (abs(bonds - 2) < 0.1)
def test_unwrap(): l = 10 box = Box([0, 0, 0], [l, l, l]) P1 = Polymer(N=20, type_bead=1, ptolerance=0, type_polymer="linear", start_id=0, lconstrain=[], gconstrain=[box]) for i in range(20): P1.coords[i][0] = i if P1.coords[i][0] > l: P1.coords[i][0] -= l print P1.coords P1.unwrap(ref=[0, 0, 0], box=box) print P1.coords assert np.sum(P1.coords[::, 0] - np.array(range(20))) < 1e-9
def test_crash(): PS = [0.2, 0.2, 0.2] PM = [10, 10.2, 0.2] PE = [0.2, 199, 19] start = Point(index=0, position=PS) middle = Point(index=39, position=PM) end = Point(index=399, position=PE) #end = Point(index=199,position=[0.2,0.2,0.2]) box = Box([-10, -10, -10], [400, 400, 400]) coords_lp, bonds, type_beads, ids = one_polymer( N=400, type_bead=1, liaison={"1-1": [1.0, 1]}, ptolerance=0, type_polymer="linear", start_id=0, lconstrain=[start, middle, end], gconstrain=[box], max_trial=500000, rc=0.5, virtual_lp=3, rigid_constrain=True)
def test_constrain_box_on_polymer(): box = Box([0,0,0],[10,10,10]) coords,bonds,type_beads,ids = one_polymer(N=200,type_bead=1,ptolerance=0,type_polymer="linear",start_id=0,gconstrain=[box]) for p in coords: assert(box.is_inside(p))
def test_lammps_poly_add_onep(): Simu = LSimu() Simu.create_polymers(NP=10,N=100,box=Box([0,0,0],[10,10,10])) Simu.add(Polymer(N=1)) Simu.generate_xyz("test/mix.xyz",Mass="one") Simu.generate_pdb("test/mix.pdb")
def test_lammps_poly_simu(): Simu = LSimu() Simu.create_polymers(NP=10,N=100,box=Box([0,0,0],[10,10,10])) Simu.generate_xyz("test/mix.xyz",Mass="one")