Esempio n. 1
0
def graft_HC_chain(save, readpoly, readnp, R1, R2):

    fin1 = open(readpoly, 'r')
    fin2 = open(readnp, 'r')
    fout = open(save, 'w')

    f1data = fin1.read()
    data1 = f1data.splitlines()
    data1 = data1[2:]

    f2data = fin2.read()
    data2 = f2data.splitlines()
    data2 = data2[2:]

    sulfur = [-1.58237, 0.899165, 0.0]

    for line in data2:
        s = line.split()
        fout.write(
            ('%s %f %f %f\n') % (s[0], float(s[1]), float(s[2]), float(s[3])))

    for line in data2:
        s = line.split()
        vec = np.sqrt((float(s[1])**2) + (float(s[2])**2) + (float(s[3])**2))
        if vec == R1:
            r1 = float(s[1]) / float(vec) + float(s[1])
            r2 = float(s[2]) / float(vec) + float(s[2])
            r3 = float(s[3]) / float(vec) + float(s[3])
            #fout.write(("S %f %f %f\n")%(r1,r2,r3))
            v = [r1, r2, r3]
            P = rp.align_vector(readpoly, v)
            for i in range(P.shape[0]):
                P[i] = np.add(v, P[i])
                #if(i==P.shape[1]-1):
                if (i == P.shape[0] - 1):
                    fout.write(
                        ('CH3 %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
                elif (i == 0):
                    fout.write(('S %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
                else:
                    fout.write(
                        ('CH2 %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
        if vec == R2:
            r1 = float(s[1]) / float(vec) + float(s[1])
            r2 = float(s[2]) / float(vec) + float(s[2])
            r3 = float(s[3]) / float(vec) + float(s[3])
            #fout.write(("S %f %f %f\n")%(r1,r2,r3))
            v = [r1, r2, r3]
            P = rp.align_vector(readpoly, v)
            for i in range(P.shape[0]):
                P[i] = np.add(v, P[i])
                #if(i==P.shape[1]-1):
                if (i == P.shape[0] - 1):
                    fout.write(
                        ('CH3 %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
                elif (i == 0):
                    fout.write(('S %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
                else:
                    fout.write(
                        ('CH2 %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
Esempio n. 2
0
def graft_HC_chain(save,readpoly,readnp,R1,R2):
    
    fin1 = open(readpoly,'r')
    fin2 = open(readnp,'r')
    fout = open(save,'w')
    
    
    f1data=fin1.read()
    data1=f1data.splitlines()
    data1=data1[2:]
    
    f2data=fin2.read()
    data2=f2data.splitlines()
    data2=data2[2:]
    
    sulfur=[-1.58237,0.899165,0.0]
    
    for line in data2:
        s=line.split()
        fout.write(('%s %f %f %f\n')%(s[0],float(s[1]),float(s[2]),float(s[3])))
        
    for line in data2:   
        s=line.split()
        vec=np.sqrt((float(s[1])**2)+(float(s[2])**2)+(float(s[3])**2))
        if vec == R1:
            r1=float(s[1])/float(vec)+float(s[1]) 
            r2=float(s[2])/float(vec)+float(s[2])
            r3=float(s[3])/float(vec)+float(s[3])
            #fout.write(("S %f %f %f\n")%(r1,r2,r3))
            v=[r1,r2,r3]
            P=rp.align_vector(readpoly,v)
            for i in range(P.shape[0]):
                P[i]=np.add(v,P[i])
                if(i==P.shape[1]-1):
                    fout.write(('CH3 %f %f %f\n')%(P[i][0],P[i][1],P[i][2]))
                elif(i==0):
                    fout.write(('S %f %f %f\n')%(P[i][0],P[i][1],P[i][2]))
                else:
                    fout.write(('CH2 %f %f %f\n')%(P[i][0],P[i][1],P[i][2]))
        if vec == R2:
            r1=float(s[1])/float(vec)+float(s[1]) 
            r2=float(s[2])/float(vec)+float(s[2])
            r3=float(s[3])/float(vec)+float(s[3])
            #fout.write(("S %f %f %f\n")%(r1,r2,r3))
            v=[r1,r2,r3]
            P=rp.align_vector(readpoly,v)
            for i in range(P.shape[0]):
                P[i]=np.add(v,P[i])
                if(i==P.shape[1]-1):
                    fout.write(('CH3 %f %f %f\n')%(P[i][0],P[i][1],P[i][2]))
                elif(i==0):
                    fout.write(('S %f %f %f\n')%(P[i][0],P[i][1],P[i][2]))  
                else:
                    fout.write(('CH2 %f %f %f\n')%(P[i][0],P[i][1],P[i][2]))
Esempio n. 3
0
def graft_square_faces(save, readpoly, readnp, R_face):
    fin1 = open(readpoly, 'r')
    fin2 = open(readnp, 'r')
    fout = open(save, 'w')

    f1data = fin1.read()
    data1 = f1data.splitlines()
    data1 = data1[2:]

    f2data = fin2.read()
    data2 = f2data.splitlines()
    data2 = data2[2:]
    #####################
    #AuS is length radial outward from face for Au-S distance
    #####################
    AuS = 1.97

    vecs = np.array([[0.0, 0.0, 0.0]])
    count = (6 * len(data1) + 6)

    Spos = R_face + AuS
    vecs = np.append(vecs, [[0.0, 0.0, Spos]], axis=0)
    vecs = np.append(vecs, [[0.0, 0.0, -Spos]], axis=0)
    vecs = np.append(vecs, [[0.0, Spos, 0.0]], axis=0)
    vecs = np.append(vecs, [[0.0, -Spos, 0.0]], axis=0)
    vecs = np.append(vecs, [[Spos, 0.0, 0.0]], axis=0)
    vecs = np.append(vecs, [[-Spos, 0.0, 0.0]], axis=0)

    fout.write(('%s\n\n') % (str(len(data2) + count)))

    for line in data2:
        s = line.split()
        fout.write(
            ('%s %f %f %f\n') % (s[0], float(s[1]), float(s[2]), float(s[3])))

    for v in range(1, vecs.shape[0]):
        P = rp.align_vector(readpoly, vecs[v])
        for x in range(P.shape[0]):
            P[x] = np.add(vecs[v], P[x])
            if (x == P.shape[0] - 1):
                fout.write(('CH3 %f %f %f\n') % (P[x][0], P[x][1], P[x][2]))
            elif (x == 0):
                fout.write(('S %f %f %f\n') % (P[x][0], P[x][1], P[x][2]))
            else:
                fout.write(('CH2 %f %f %f\n') % (P[x][0], P[x][1], P[x][2]))
Esempio n. 4
0
"""

import sys
import os
import numpy as np

import rotate_polymer as rp

#############################
## Number of repeating units
#############################

n = 10

##############
### v must be [x,y,z]
################
v = [-1, -1, -1]

#################
## File to read
#################

inputfile = 'HC_chain_n' + str(n) + '.xyz'

#################
## Call Function
#################

rp.align_vector(inputfile, v)
Esempio n. 5
0
import os
import numpy as np

import rotate_polymer as rp

#############################
## Number of repeating units
#############################

n=10

##############
### v must be [x,y,z]
################
v=[-1,-1,-1]

#################
## File to read
#################

inputfile='HC_chain_n' + str(n) +'.xyz'

#################
## Call Function
#################

rp.align_vector(inputfile,v)



Esempio n. 6
0
def graft_HC_hex(save, readpoly, readnp, Rcf, Rct):

    fin1 = open(readpoly, 'r')
    fin2 = open(readnp, 'r')
    fout = open(save, 'w')

    f1data = fin1.read()
    data1 = f1data.splitlines()
    data1 = data1[2:]
    print('length of poly is ' + str(len(data1) + 1))

    f2data = fin2.read()
    data2 = f2data.splitlines()
    data2 = data2[2:]

    centers = np.array([[0.0, 0.0, 0.0]])
    centersout = np.array([[0.0, 0.0, 0.0]])
    tophexes = np.array([[0.0, 0.0, 0.0]])
    bothexes = np.array([[0.0, 0.0, 0.0]])

    count = int(8 * len(data1) + 1)
    centers = np.append(centers, [[Rcf, Rcf, Rcf]], axis=0)
    centers = np.append(centers, [[Rcf, Rcf, -Rcf]], axis=0)
    centers = np.append(centers, [[Rcf, -Rcf, -Rcf]], axis=0)
    centers = np.append(centers, [[Rcf, -Rcf, Rcf]], axis=0)
    centers = np.append(centers, [[-Rcf, Rcf, Rcf]], axis=0)
    centers = np.append(centers, [[-Rcf, -Rcf, Rcf]], axis=0)
    centers = np.append(centers, [[-Rcf, Rcf, -Rcf]], axis=0)
    centers = np.append(centers, [[-Rcf, -Rcf, -Rcf]], axis=0)

    out = 1.137380030
    centersout = np.append(centersout, [[Rcf + out, Rcf + out, Rcf + out]],
                           axis=0)
    centersout = np.append(centersout, [[Rcf + out, Rcf + out, -Rcf - out]],
                           axis=0)
    centersout = np.append(centersout, [[Rcf + out, -Rcf - out, -Rcf - out]],
                           axis=0)
    centersout = np.append(centersout, [[Rcf + out, -Rcf - out, Rcf + out]],
                           axis=0)
    centersout = np.append(centersout, [[-Rcf - out, Rcf + out, Rcf + out]],
                           axis=0)
    centersout = np.append(centersout, [[-Rcf - out, -Rcf - out, Rcf + out]],
                           axis=0)
    centersout = np.append(centersout, [[-Rcf - out, Rcf + out, -Rcf - out]],
                           axis=0)
    centersout = np.append(centersout, [[-Rcf - out, -Rcf - out, -Rcf - out]],
                           axis=0)

    for line in data2:
        s = line.split()
        csv = [s[1], s[2], s[3]]
        cf = LA.norm(csv)
        vec = np.sqrt((float(s[1])**2) + (float(s[2])**2) + (float(s[3])**2))
        if vec == Rct and float(s[3]) >= 0.0 and float(s[2]) >= 0 and float(
                s[1]) >= 0:
            count += int((2 / 3.) * len(data1) + 1)
            r1 = float(s[1])
            r2 = float(s[2])
            r3 = float(s[3])
            v = [[r1, r2, r3]]
            for rv in range(1, centers.shape[0]):
                diff = np.subtract(centers[rv], v)
                csv = [centers[rv][0], centers[rv][1], centers[rv][2]]
                cf = LA.norm(csv)
                if LA.norm(diff) <= 2.0:
                    cfv = [
                        float(csv[0]) / float(cf),
                        float(csv[1]) / float(cf),
                        float(csv[2]) / float(cf)
                    ]
                    addout = np.multiply(1.97, cfv)
                    tophexes = np.append(tophexes,
                                         np.add(addout,
                                                np.subtract(v, 1.393 * diff)),
                                         axis=0)
                    tophexes = np.append(tophexes,
                                         np.add(addout, np.add(v, 4 * diff)),
                                         axis=0)
        if vec == Rct and float(s[3]) >= 0.0 and float(s[2]) <= 0 and float(
                s[1]) <= 0:
            count += int((2 / 3.) * len(data1) + 1)
            r1 = float(s[1])
            r2 = float(s[2])
            r3 = float(s[3])
            v = [[r1, r2, r3]]
            for rv in range(1, centers.shape[0]):
                diff = np.subtract(centers[rv], v)
                csv = [centers[rv][0], centers[rv][1], centers[rv][2]]
                cf = LA.norm(csv)
                if LA.norm(diff) <= 2.0:
                    cfv = [
                        float(csv[0]) / float(cf),
                        float(csv[1]) / float(cf),
                        float(csv[2]) / float(cf)
                    ]
                    addout = np.multiply(1.97, cfv)
                    tophexes = np.append(tophexes,
                                         np.add(addout,
                                                np.subtract(v, 1.393 * diff)),
                                         axis=0)
                    tophexes = np.append(tophexes,
                                         np.add(addout, np.add(v, 4 * diff)),
                                         axis=0)
        if vec == Rct and float(s[3]) <= 0.0 and float(s[2]) >= 0 and float(
                s[1]) <= 0:
            count += int((2 / 3.) * len(data1) + 1)
            r1 = float(s[1])
            r2 = float(s[2])
            r3 = float(s[3])
            v = [[r1, r2, r3]]
            for rv in range(1, centers.shape[0]):
                diff = np.subtract(centers[rv], v)
                csv = [centers[rv][0], centers[rv][1], centers[rv][2]]
                cf = LA.norm(csv)
                if LA.norm(diff) <= 2.0:
                    cfv = [
                        float(csv[0]) / float(cf),
                        float(csv[1]) / float(cf),
                        float(csv[2]) / float(cf)
                    ]
                    addout = np.multiply(1.97, cfv)
                    tophexes = np.append(tophexes,
                                         np.add(addout,
                                                np.subtract(v, 1.393 * diff)),
                                         axis=0)
                    tophexes = np.append(tophexes,
                                         np.add(addout, np.add(v, 4 * diff)),
                                         axis=0)
        if vec == Rct and float(s[3]) <= 0.0 and float(s[2]) <= 0 and float(
                s[1]) >= 0:
            count += int((2 / 3.) * len(data1) + 1)
            r1 = float(s[1])
            r2 = float(s[2])
            r3 = float(s[3])
            v = [[r1, r2, r3]]
            for rv in range(1, centers.shape[0]):
                diff = np.subtract(centers[rv], v)
                csv = [centers[rv][0], centers[rv][1], centers[rv][2]]
                cf = LA.norm(csv)
                if LA.norm(diff) <= 2.0:
                    cfv = [
                        float(csv[0]) / float(cf),
                        float(csv[1]) / float(cf),
                        float(csv[2]) / float(cf)
                    ]
                    addout = np.multiply(1.97, cfv)
                    tophexes = np.append(tophexes,
                                         np.add(addout,
                                                np.subtract(v, 1.393 * diff)),
                                         axis=0)
                    tophexes = np.append(tophexes,
                                         np.add(addout, np.add(v, 4 * diff)),
                                         axis=0)
        V = [[0, 0, 0]]
        if vec == Rct and float(s[3]) >= 0.0 and float(s[2]) >= 0 and float(
                s[1]) <= 0:
            count += int((1 / 3.) * len(data1) + 1)
            r1 = float(s[1])
            r2 = float(s[2])
            r3 = float(s[3])
            v = [[r1, r2, r3]]
            for rv in range(1, centers.shape[0]):
                k = np.subtract(V, centers[rv])
                knor = LA.norm(k)
                kt = [
                    float(k[0][0]) / float(knor),
                    float(k[0][1]) / float(knor),
                    float(k[0][2]) / float(knor)
                ]
                K = [[0, -kt[2], kt[1]], [kt[2], 0, -kt[0]],
                     [-kt[1], kt[0], 0]]
                ###
                csv = [centers[rv][0], centers[rv][1], centers[rv][2]]
                cf = LA.norm(csv)
                cfv = [
                    float(csv[0]) / float(cf),
                    float(csv[1]) / float(cf),
                    float(csv[2]) / float(cf)
                ]
                ###
                v1 = np.subtract(centers[rv], v)
                vn = [v1[0][0], v1[0][1], v1[0][2]]
                vnor = LA.norm(vn)
                vt = [
                    float(vn[0]) / float(vnor),
                    float(vn[1]) / float(vnor),
                    float(vn[2]) / float(vnor)
                ]
                ###
                theta = np.pi / 7
                theta2 = 2 * np.pi - theta
                R = np.add(
                    np.identity(3),
                    np.add(np.multiply(np.sin(theta), K),
                           np.multiply((1 - np.cos(theta)), np.dot(K, K))))
                R2 = np.add(
                    np.identity(3),
                    np.add(np.multiply(np.sin(theta2), K),
                           np.multiply((1 - np.cos(theta2)), np.dot(K, K))))
                if LA.norm(v1) <= 2.0:
                    addout = np.multiply(1.97, cfv)
                    nnfac = 4.49429
                    u1 = np.add(np.multiply(Rct, cfv), np.multiply(nnfac, vt))
                    u = [u1[0], u1[1], u1[2]]
                    vr = np.dot(R, u)
                    vr2 = np.dot(R2, u)
                    bothexes = np.append(bothexes,
                                         np.add([addout], [vr]),
                                         axis=0)
                    bothexes = np.append(bothexes,
                                         np.add([addout], [vr2]),
                                         axis=0)
        V = [[0, 0, 0]]
        if vec == Rct and float(s[3]) >= 0.0 and float(s[2]) <= 0 and float(
                s[1]) >= 0:
            count += int((1 / 3.) * len(data1) + 1)
            r1 = float(s[1])
            r2 = float(s[2])
            r3 = float(s[3])
            v = [[r1, r2, r3]]
            for rv in range(1, centers.shape[0]):
                k = np.subtract(V, centers[rv])
                knor = LA.norm(k)
                kt = [
                    float(k[0][0]) / float(knor),
                    float(k[0][1]) / float(knor),
                    float(k[0][2]) / float(knor)
                ]
                K = [[0, -kt[2], kt[1]], [kt[2], 0, -kt[0]],
                     [-kt[1], kt[0], 0]]
                ###
                csv = [centers[rv][0], centers[rv][1], centers[rv][2]]
                cf = LA.norm(csv)
                cfv = [
                    float(csv[0]) / float(cf),
                    float(csv[1]) / float(cf),
                    float(csv[2]) / float(cf)
                ]
                ###
                v1 = np.subtract(centers[rv], v)
                vn = [v1[0][0], v1[0][1], v1[0][2]]
                vnor = LA.norm(vn)
                vt = [
                    float(vn[0]) / float(vnor),
                    float(vn[1]) / float(vnor),
                    float(vn[2]) / float(vnor)
                ]
                ###
                theta = np.pi / 7
                theta2 = 2 * np.pi - theta
                R = np.add(
                    np.identity(3),
                    np.add(np.multiply(np.sin(theta), K),
                           np.multiply((1 - np.cos(theta)), np.dot(K, K))))
                R2 = np.add(
                    np.identity(3),
                    np.add(np.multiply(np.sin(theta2), K),
                           np.multiply((1 - np.cos(theta2)), np.dot(K, K))))
                if LA.norm(v1) <= 2.0:
                    addout = np.multiply(1.97, cfv)
                    nnfac = 4.49429
                    u1 = np.add(np.multiply(Rct, cfv), np.multiply(nnfac, vt))
                    u = [u1[0], u1[1], u1[2]]
                    vr = np.dot(R, u)
                    vr2 = np.dot(R2, u)
                    bothexes = np.append(bothexes,
                                         np.add([addout], [vr]),
                                         axis=0)
                    bothexes = np.append(bothexes,
                                         np.add([addout], [vr2]),
                                         axis=0)
        V = [[0, 0, 0]]
        if vec == Rct and float(s[3]) <= 0.0 and float(s[2]) <= 0 and float(
                s[1]) <= 0:
            count += int((1 / 3.) * len(data1) + 1)
            r1 = float(s[1])
            r2 = float(s[2])
            r3 = float(s[3])
            v = [[r1, r2, r3]]
            for rv in range(1, centers.shape[0]):
                k = np.subtract(V, centers[rv])
                knor = LA.norm(k)
                kt = [
                    float(k[0][0]) / float(knor),
                    float(k[0][1]) / float(knor),
                    float(k[0][2]) / float(knor)
                ]
                K = [[0, -kt[2], kt[1]], [kt[2], 0, -kt[0]],
                     [-kt[1], kt[0], 0]]
                ###
                csv = [centers[rv][0], centers[rv][1], centers[rv][2]]
                cf = LA.norm(csv)
                cfv = [
                    float(csv[0]) / float(cf),
                    float(csv[1]) / float(cf),
                    float(csv[2]) / float(cf)
                ]
                ###
                v1 = np.subtract(centers[rv], v)
                vn = [v1[0][0], v1[0][1], v1[0][2]]
                vnor = LA.norm(vn)
                vt = [
                    float(vn[0]) / float(vnor),
                    float(vn[1]) / float(vnor),
                    float(vn[2]) / float(vnor)
                ]
                ###
                theta = np.pi / 7
                theta2 = 2 * np.pi - theta
                R = np.add(
                    np.identity(3),
                    np.add(np.multiply(np.sin(theta), K),
                           np.multiply((1 - np.cos(theta)), np.dot(K, K))))
                R2 = np.add(
                    np.identity(3),
                    np.add(np.multiply(np.sin(theta2), K),
                           np.multiply((1 - np.cos(theta2)), np.dot(K, K))))
                if LA.norm(v1) <= 2.0:
                    addout = np.multiply(1.97, cfv)
                    nnfac = 4.49429
                    u1 = np.add(np.multiply(Rct, cfv), np.multiply(nnfac, vt))
                    u = [u1[0], u1[1], u1[2]]
                    vr = np.dot(R, u)
                    vr2 = np.dot(R2, u)
                    bothexes = np.append(bothexes,
                                         np.add([addout], [vr]),
                                         axis=0)
                    bothexes = np.append(bothexes,
                                         np.add([addout], [vr2]),
                                         axis=0)
        V = [[0, 0, 0]]
        if vec == Rct and float(s[3]) <= 0.0 and float(s[2]) >= 0 and float(
                s[1]) >= 0:
            count += int((1 / 3.) * len(data1) + 1)
            r1 = float(s[1])
            r2 = float(s[2])
            r3 = float(s[3])
            v = [[r1, r2, r3]]
            for rv in range(1, centers.shape[0]):
                k = np.subtract(V, centers[rv])
                knor = LA.norm(k)
                kt = [
                    float(k[0][0]) / float(knor),
                    float(k[0][1]) / float(knor),
                    float(k[0][2]) / float(knor)
                ]
                K = [[0, -kt[2], kt[1]], [kt[2], 0, -kt[0]],
                     [-kt[1], kt[0], 0]]
                ###
                csv = [centers[rv][0], centers[rv][1], centers[rv][2]]
                cf = LA.norm(csv)
                cfv = [
                    float(csv[0]) / float(cf),
                    float(csv[1]) / float(cf),
                    float(csv[2]) / float(cf)
                ]
                ###
                v1 = np.subtract(centers[rv], v)
                vn = [v1[0][0], v1[0][1], v1[0][2]]
                vnor = LA.norm(vn)
                vt = [
                    float(vn[0]) / float(vnor),
                    float(vn[1]) / float(vnor),
                    float(vn[2]) / float(vnor)
                ]
                ###
                theta = np.pi / 7
                theta2 = 2 * np.pi - theta
                R = np.add(
                    np.identity(3),
                    np.add(np.multiply(np.sin(theta), K),
                           np.multiply((1 - np.cos(theta)), np.dot(K, K))))
                R2 = np.add(
                    np.identity(3),
                    np.add(np.multiply(np.sin(theta2), K),
                           np.multiply((1 - np.cos(theta2)), np.dot(K, K))))
                if LA.norm(v1) <= 2.0:
                    addout = np.multiply(1.97, cfv)
                    nnfac = 4.49429
                    u1 = np.add(np.multiply(Rct, cfv), np.multiply(nnfac, vt))
                    u = [u1[0], u1[1], u1[2]]
                    vr = np.dot(R, u)
                    vr2 = np.dot(R2, u)
                    bothexes = np.append(bothexes,
                                         np.add([addout], [vr]),
                                         axis=0)
                    bothexes = np.append(bothexes,
                                         np.add([addout], [vr2]),
                                         axis=0)

    fout.write(('%s\n\n') % (str(len(data2) + count)))

    for line in data2:
        s = line.split()
        fout.write(
            ('%s %f %f %f\n') % (s[0], float(s[1]), float(s[2]), float(s[3])))

    for v in range(1, centersout.shape[0]):
        P = rp.align_vector(readpoly, centersout[v])
        for i in range(P.shape[0]):
            P[i] = np.add(centersout[v], P[i])
            if (i == P.shape[0] - 1):
                fout.write(('CH3 %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
            elif (i == 0):
                fout.write(('S %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
            else:
                fout.write(('CH2 %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))

    for v in range(1, tophexes.shape[0]):
        P = rp.align_vector(readpoly, tophexes[v])
        for i in range(P.shape[0]):
            P[i] = np.add(tophexes[v], P[i])
            if (i == P.shape[0] - 1):
                fout.write(('CH3 %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
            elif (i == 0):
                fout.write(('S %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
            else:
                fout.write(('CH2 %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))

    for v in range(1, bothexes.shape[0]):
        P = rp.align_vector(readpoly, bothexes[v])
        for i in range(P.shape[0]):
            P[i] = np.add(bothexes[v], P[i])
            if (i == P.shape[0] - 1):
                fout.write(('CH3 %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
            elif (i == 0):
                fout.write(('S %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
            else:
                fout.write(('CH2 %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
Esempio n. 7
0
def graft_PEO_hex(save, readpoly, readnp, R1, R2):

    fin1 = open(readpoly, 'r')
    fin2 = open(readnp, 'r')
    fout = open(save, 'w')

    f1data = fin1.read()
    data1 = f1data.splitlines()
    data1 = data1[2:]
    print('length of poly is ' + str(len(data1)))

    f2data = fin2.read()
    data2 = f2data.splitlines()
    data2 = data2[2:]

    centers = np.array([[0.0, 0.0, 0.0]])
    hexes = np.array([[0.0, 0.0, 0.0]])
    count = 0

    for line in data2:
        s = line.split()
        vec = np.sqrt((float(s[1])**2) + (float(s[2])**2) + (float(s[3])**2))
        if vec == R1:
            count += int(len(data1) + 1)
            r1 = float(s[1]) / float(vec) + float(s[1])
            r2 = float(s[2]) / float(vec) + float(s[2])
            r3 = float(s[3]) / float(vec) + float(s[3])
            v = [[r1, r2, r3]]
            centers = np.append(centers, v, axis=0)

        if vec == R2:
            count += int(len(data1) + 1)
            r1 = float(s[1]) / float(vec) + float(s[1])
            r2 = float(s[2]) / float(vec) + float(s[2])
            r3 = float(s[3]) / float(vec) + float(s[3])
            v = [[r1, r2, r3]]
            hexes = np.append(hexes, v, axis=0)

    fout.write(('%s\n\n') % (str(len(data2) + count)))

    for line in data2:
        s = line.split()
        fout.write(
            ('%s %f %f %f\n') % (s[0], float(s[1]), float(s[2]), float(s[3])))

    for v in range(1, centers.shape[0]):
        P = rp.align_vector(readpoly, centers[v])
        for i in range(P.shape[0]):
            P[i] = np.add(centers[v], P[i])
            if (i == P.shape[0] - 1):
                fout.write(('OH %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
            elif (i == 0):
                fout.write(('S %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
            else:
                fout.write(('O %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))

    newhexes = np.array([[0.0, 0.0, 0.0]])
    for v in range(1, hexes.shape[0]):
        for i in range(1, centers.shape[0]):
            findhexes = np.subtract(centers[i], hexes[v])
            norm = np.sqrt(findhexes[0]**2 + findhexes[1]**2 + findhexes[2]**2)
            if norm <= 3.18 / (3.96 / np.sqrt(2)):
                newhexes = np.append(
                    newhexes,
                    [np.add(centers[i], np.multiply(1.28931, findhexes))],
                    axis=0)

    for v in range(1, newhexes.shape[0]):
        P = rp.align_vector(readpoly, newhexes[v])
        for i in range(P.shape[0]):
            P[i] = np.add(newhexes[v], P[i])
            #if(i==P.shape[1]-1):
            if (i == P.shape[0] - 1):
                fout.write(('OH %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
            elif (i == 0):
                fout.write(('S %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
            else:
                fout.write(('O %f %f %f\n') % (P[i][0], P[i][1], P[i][2]))
Esempio n. 8
0
def graft_square_faces(save, readpoly, readnp, R, sulfur_distance):
    fin1 = open(readpoly, 'r')
    fin2 = open(readnp, 'r')
    fout = open(save, 'w')

    f1data = fin1.read()
    data1 = f1data.splitlines()
    data1 = data1[2:]

    f2data = fin2.read()
    data2 = f2data.splitlines()
    data2 = data2[2:]
    #####################
    #AuSmultiplies a unit vestor to control the AuS initial distance
    ## AuS^2+.25^2= actual AuS distance ^2
    ###############3
    AuS = 1
    s_s = sulfur_distance / np.sqrt(2)

    ##once the positions of the middle gold atom in the square face is found, four
    ##chians will be started at the s_s offset away

    vecs = np.array([[0.0, 0.0, 0.0]])
    counter = 0
    for line in data2:
        s = line.split()
        vec = np.sqrt((float(s[1])**2) + (float(s[2])**2) + (float(s[3])**2))
        if vec == R:
            counter += int(4 * (len(data1) + 1))
            for i in range(0, 4):
                if (float(s[1]) != 0):
                    r2 = s_s * (int(i < 2) * (1 - (2 * i))) + float(s[2])
                    r3 = s_s * int(i > 1) * (5 - (2 * i)) + float(s[3])
                    r1 = AuS * float(s[1]) / float(vec) + float(s[1])
                elif (float(s[2]) != 0):
                    r1 = s_s * (int(i < 2) * (1 - (2 * i))) + float(s[1])
                    r3 = s_s * int(i > 1) * (5 - (2 * i)) + float(s[3])
                    r2 = AuS * float(s[2]) / float(vec) + float(s[2])
                else:
                    r1 = s_s * (int(i < 2) * (1 - (2 * i))) + float(s[1])
                    r2 = s_s * int(i > 1) * (5 - (2 * i)) + float(s[2])
                    r3 = AuS * float(s[3]) / float(vec) + float(s[3])

                vecs = np.append(vecs, [[r1, r2, r3]], axis=0)

    fout.write(('%s\n\n') % (str(len(data2) + counter)))

    for line in data2:
        s = line.split()
        fout.write(
            ('%s %f %f %f\n') % (s[0], float(s[1]), float(s[2]), float(s[3])))

    for v in range(1, vecs.shape[0]):
        P = rp.align_vector(readpoly, vecs[v])
        for x in range(P.shape[0]):
            P[x] = np.add(vecs[v], P[x])
            if (x == P.shape[0] - 1):
                fout.write(('OH %f %f %f\n') % (P[x][0], P[x][1], P[x][2]))
            elif (x == 0):
                fout.write(('S %f %f %f\n') % (P[x][0], P[x][1], P[x][2]))
            else:
                fout.write(('O %f %f %f\n') % (P[x][0], P[x][1], P[x][2]))