예제 #1
0
def gennewcoord(pbc):
    #generate random vector on 1 sphere
    orient = usefulmath.vec_random()
    orient = usefulmath.vec_normalize(orient)

    #generate position
    pos = [random.random()*float(pbc[0]),random.random()*float(pbc[1]),random.random()*float(pbc[2])]
    
    #generate patch (perpendicular to orientation of cylinder)
    patch = usefulmath.perp_vec(orient)
    patch = usefulmath.vec_normalize(patch)
    
    #return [pos,orient]
    return [pos,orient,patch]
예제 #2
0
def gennewcoord(pbc,dist):
    #generate random vector on 1 sphere
    orient=usefulmath.vec_random()
    orient=usefulmath.vec_normalize(orient)

    dist=float(dist);
    dist2=2.0*dist;

    #generate position
    pos=[dist+random.random()*(float(pbc[0])-dist2),dist+random.random()*(float(pbc[1])-dist2),dist+random.random()*(float(pbc[2])-dist2)]
    
    #generate patch (perpendicular to orientation of cylinder)
    patch=usefulmath.perp_vec(orient)
    patch=usefulmath.vec_normalize(patch)
    
    #return [pos,orient]
    return [pos,orient,patch]
예제 #3
0
def datatransform(data,leng,patch):
    newdata=[]
    for frame in data:
	newframe=[]
	for line in frame:
	    [x,y,z,vx,vy,vz,px,py,pz]=line[:]
	    vec=usefulmath.vec_normalize([vx,vy,vz])
	    newframe.append([x+leng/2*vec[0],y+leng/2*vec[1],z+leng/2*vec[2]])
	    newframe.append([x-leng/2*vec[0],y-leng/2*vec[1],z-leng/2*vec[2]])
	newdata.append(newframe)

    return newdata
예제 #4
0
def datatransform(data, leng, patch):
    newdata = []
    for frame in data:
        newframe = []
        for line in frame:
            [x, y, z, vx, vy, vz, px, py, pz] = line[:]
            vec = usefulmath.vec_normalize([vx, vy, vz])
            newframe.append([
                x + leng / 2 * vec[0], y + leng / 2 * vec[1],
                z + leng / 2 * vec[2]
            ])
            newframe.append([
                x - leng / 2 * vec[0], y - leng / 2 * vec[1],
                z - leng / 2 * vec[2]
            ])
        newdata.append(newframe)

    return newdata
예제 #5
0
def datatransform(data,leng,patch):
    newdata=[]
    for frame in data:
	newframe=[]
	for line in frame:
	    [x,y,z,vx,vy,vz,px,py,pz]=line[:]
	    vec=usefulmath.vec_normalize([vx,vy,vz])
	    newframe.append([x+leng/2*vec[0],y+leng/2*vec[1],z+leng/2*vec[2]])
	    newframe.append([x-leng/2*vec[0],y-leng/2*vec[1],z-leng/2*vec[2]])
	    patchmove=10*0.5*math.cos((patch+10)/2/180*math.pi)
	    newx=x+leng/2*vec[0]+patchmove*px
	    newy=y+leng/2*vec[1]+patchmove*py
	    newz=z+leng/2*vec[2]+patchmove*pz
	    newframe.append([newx,newy,newz])
	    newx=x-leng/2*vec[0]+patchmove*px
	    newy=y-leng/2*vec[1]+patchmove*py
	    newz=z-leng/2*vec[2]+patchmove*pz
	    newframe.append([newx,newy,newz])
	newdata.append(newframe)

    return newdata
예제 #6
0
def write_data(data,box,particles, types, geotypes, params,outfilename,outfilename2, switch, switchtypes, switchfile):
    f = open(outfilename, 'w')
    outstring=""
    if (switch):
	swstring=""
	sf = open(switchfile, 'w')
    #DEBUG
    #print("Length of types")
    #print(len(types))
    #print("Len Data")
    #print(len(data))
    #print(types)
    #print(geotypes)
    for i in range(len(data)):
	newline="CRYST1 %8.3f %8.3f %8.3f  90.00  90.00  90.00 P 1           1\n" % (box[i][0],box[i][1],box[i][2])
	outstring=outstring+newline
	frame=data[i]
	#print("len frame")
	#print(len(frame))
	atm=1
	for j in range(len(frame)):
	    [x,y,z,vx,vy,vz,px,py,pz,sw]=frame[j][:]
	    [x,y,z] = usefulmath.usepbc([x,y,z],box[i])
	    #if (types[j] <SP):
	    #print("j : %d\n" % j)
	    if (convert_geotype(geotypes[particles[j]]) <SP):
		# Handle the switching
		csw = 2 * sw + types[particles[j]] +0
		psw = 2 * sw + types[particles[j]] +1
		tsw = 2 * sw + types[particles[j]] +2
		if (switch):
		    swstring = swstring + "%d %d %d %d " % (csw, csw, psw, psw)
		vec=usefulmath.vec_normalize([vx,vy,vz])
		#print head
		leng = params[particles[j]][6]
		nx=x+leng/2*vec[0]
		ny=y+leng/2*vec[1]
		nz=z+leng/2*vec[2]
		#print("max j: %d; j: %d" % (len(frame), j))
		newline="ATOM  %5d  C%1d  PSC F%4d    % 8.2f% 8.2f% 8.2f  1.00%6.2f\n" % (atm,particles[j],(j+1)%1000,nx,ny,nz,csw)
		outstring=outstring+newline
		atm=atm+1
		#print tail
		nx=x-leng/2*vec[0]
		ny=y-leng/2*vec[1]
		nz=z-leng/2*vec[2]
		newline="ATOM  %5d  C%1d  PSC F%4d    % 8.2f% 8.2f% 8.2f  1.00%6.2f\n" % (atm,particles[j],(j+1)%1000,nx,ny,nz,csw)
		outstring=outstring+newline
		atm=atm+1
		#print patch
		#patch=params[types[j]][3]+2*params[types[j]][4]
		patch=params[particles[j]][4]+2*params[particles[j]][5]
		#print headpatch
		patchmove=math.fabs(0.5*math.cos((patch+10*pow(patch/180,2))/360*math.pi)) # displacement
		#patchmove= params[particles[j]][2] * patch/ 1080 + params[particles[j]][2] / 12 # displacement
		# The displacement varries between sigma / 12 and sigma / 4 depending on the angle
		nx=x+leng/2*vec[0]+patchmove*px
		ny=y+leng/2*vec[1]+patchmove*py
		nz=z+leng/2*vec[2]+patchmove*pz
		newline="ATOM  %5d  P%1d  PSC F%4d    % 8.2f% 8.2f% 8.2f  1.00%6.2f\n" % (atm,particles[j],(j+1)%1000,nx,ny,nz,psw)
		outstring=outstring+newline
		atm=atm+1
		#print tailpatch
		nx=x-leng/2*vec[0]+patchmove*px
		ny=y-leng/2*vec[1]+patchmove*py
		nz=z-leng/2*vec[2]+patchmove*pz
		newline="ATOM  %5d  P%1d  PSC F%4d    % 8.2f% 8.2f% 8.2f  1.00%6.2f\n" % (atm,particles[j],(j+1)%1000,nx,ny,nz,psw)
		outstring=outstring+newline
		atm=atm+1
		if (convert_geotype(geotypes[particles[j]]) >=TPSC):
		    #print second patch
		    if (switch):
			swstring = swstring + "%d %d " % (tsw, tsw)
		    vec2=[px,py,pz]
		    vec2=usefulmath.rotatevec(vec2,vec,params[particles[j]][7])
		    patch=params[particles[j]][8]+2*params[particles[j]][9]
		    #print headpatch
		    patchmove=0.5*math.cos((patch+10*pow(patch/180,2))/360*math.pi) # displacement
		    #patchmove= params[particles[j]][2] * patch/ 1080 + params[particles[j]][2] / 12 # displacement
		    # The displacement varries between sigma / 12 and sigma / 4 depending on the angle
		    nx=x+leng/2*vec[0]+patchmove*vec2[0]
		    ny=y+leng/2*vec[1]+patchmove*vec2[1]
		    nz=z+leng/2*vec[2]+patchmove*vec2[2]
		    newline="ATOM  %5d  T%1d  PSC F%4d    % 8.2f% 8.2f% 8.2f  1.00%6.2f\n" % (atm,particles[j],(j+1)%1000,nx,ny,nz,tsw)
		    outstring=outstring+newline
		    atm=atm+1
		    #print tailpatch
		    nx=x-leng/2*vec[0]+patchmove*vec2[0]
		    ny=y-leng/2*vec[1]+patchmove*vec2[1]
		    nz=z-leng/2*vec[2]+patchmove*vec2[2]
		    newline="ATOM  %5d  T%1d  PSC F%4d    % 8.2f% 8.2f% 8.2f  1.00%6.2f\n" % (atm,particles[j],(j+1)%1000,nx,ny,nz,tsw)
		    outstring=outstring+newline
		    atm=atm+1
		    
	    else:
		#print sphere
		nx=x
		ny=y
		nz=z
		newline="ATOM  %5d  S%1d  PSC F%4d    % 8.2f% 8.2f% 8.2f  1.00%6.2f\n" % (atm,particles[j]%SP,(j+1)%1000,nx,ny,nz,0)
		atm=atm+1
		outstring=outstring+newline
	outstring=outstring+"END\n"
	if (switch):
	    swstring = swstring + "\n"
    f.write(outstring)
    f.close()
    if (switch):
	sf.write(swstring)
	sf.close()

    return 0