Esempio n. 1
0
def createXYZFile(fp, model, atomsIndexes, xyzFile, options):
    """
    Function utilizes frames, model and atomsIndexes to create xyzFile 
    """
    startTime = time()
    while True:  # loop over trajectory
        xyzFrame = XYZFrame()

        xyzFrame.comment = "%.3f,%.3f,%.3f" % (
            model.box[0][0], model.box[1][1], model.box[2][2])
        #comment = boxSize

        frame = readXTCFrame(fp)

        if not frame:
            break  # end of trajectory or error
        model.update(frame)  # update the model data with coords, box

        for atomIndex in atomsIndexes:
            model.atoms[atomIndex - 1].x[2] = 0.
            xyzAtom = XYZAtom(model.atoms[atomIndex - 1].resname,
                              *model.atoms[atomIndex - 1].x)
            xyzFrame.atoms.append(xyzAtom)
        xyzFile.addFrame(xyzFrame)
        if options.verbose:
            delLine()
            print "time = %g step = %g" % (frame['time'], frame['step']),

    xyzFile.save()
    print "Done. Execution time=%f" % (time() - startTime)
Esempio n. 2
0
def main(argv = None):
    
    options = parseCommandLine()

    xyzFile, datFile = openFiles(options)
    frame = xyzFile.nextFrame()


    frameCounter= 1
    binSize = 0.02
    boxSize = max([vectorLength(v) for v in frame.boxVectors])
    hist = calcHist(frame, propagateThroughPBC(frame.atoms, frame.boxVectors), binSize, boxSize, options)
    
    frame = xyzFile.nextFrame()
    startTime = time()
    while not frame is None:
        if options.verbose:
            delLine()
            print frameCounter,
        newHist = calcHist(frame, propagateThroughPBC(frame.atoms, frame.boxVectors), binSize, boxSize, options)
        for i in range(len(hist)):
            hist[i] += newHist[i]
            
        frameCounter += 1
        frame = xyzFile.nextFrame()
    for i in range(len(hist)):
        datFile.write('%f %f\n' %(i * binSize, hist[i] / float(frameCounter)))
    datFile.close()
    print time() - startTime
Esempio n. 3
0
def createXYZFile(fp, model, atomsIndexes, xyzFile, options):
    """
    Function utilizes frames, model and atomsIndexes to create xyzFile 
    """
    startTime = time()
    while True:                     # loop over trajectory
        xyzFrame = XYZFrame()
        
        xyzFrame.comment = "%.3f,%.3f,%.3f" %  (model.box[0][0], 
                                          model.box[1][1], model.box[2][2]) 
        #comment = boxSize
        
        frame = readXTCFrame(fp)
        
        if not frame:
            break               # end of trajectory or error
        model.update(frame)      # update the model data with coords, box
        
        
        for atomIndex in atomsIndexes:
                model.atoms[atomIndex - 1].x[2] = 0.
                xyzAtom = XYZAtom(model.atoms[atomIndex - 1].resname, 
                                    *model.atoms[atomIndex - 1].x)
                xyzFrame.atoms.append(xyzAtom)
        xyzFile.addFrame(xyzFrame)
        if options.verbose:
            delLine()
            print "time = %g step = %g" % (frame['time'],frame['step']),

    xyzFile.save()
    print "Done. Execution time=%f" % (time() - startTime)    
Esempio n. 4
0
def main(argv=None):

    options = parseCommandLine()

    xyzFile, datFile = openFiles(options)
    frame = xyzFile.nextFrame()

    frameCounter = 1
    binSize = 0.02
    boxSize = max([vectorLength(v) for v in frame.boxVectors])
    hist = calcHist(frame, propagateThroughPBC(frame.atoms, frame.boxVectors),
                    binSize, boxSize, options)

    frame = xyzFile.nextFrame()
    startTime = time()
    while not frame is None:
        if options.verbose:
            delLine()
            print frameCounter,
        newHist = calcHist(frame,
                           propagateThroughPBC(frame.atoms, frame.boxVectors),
                           binSize, boxSize, options)
        for i in range(len(hist)):
            hist[i] += newHist[i]

        frameCounter += 1
        frame = xyzFile.nextFrame()
    for i in range(len(hist)):
        datFile.write('%f %f\n' % (i * binSize, hist[i] / float(frameCounter)))
    datFile.close()
    print time() - startTime
Esempio n. 5
0
def main():
    
    options = parseCommandLine()
    avgArea = getAvgSize(options.inXyzFilename)
    print avgArea
    lattBoxSize = ((2 * avgArea) / (3**(1/2.)) )**(1/2.) #area of parallelogram
    print lattBoxSize
    inFile = XYZFile(options.inXyzFilename)
    latt = HexLattice(int(options.lattSize), (0,0), (lattBoxSize, lattBoxSize))

    lattProj = NearestNeighborLatticeProj(inFile, latt)
    clearFile(options.outXyzFilename)
    outFile = XYZFile(options.outXyzFilename)
    i = 0
    startTime = time()
    errors = []
    #lattProj = LatticeProjectorSimple(inFile, latt)
    while True:
        if options.verbose:
	    delLine()
	    if i > 0: midTime = (time() - startTime) / i
	    else: midTime = 0
	    print i, "Avg time per frame: ", midTime,
	    sys.stdout.flush()
        projLattice = lattProj.next()
        if projLattice is None:
            break
        frame = projLattice.frame
        if options.reference:
            frame.atoms.extend(projLattice.refFrame.atoms)
	    symb = "DOPC"
	    length = len(frame.atoms)
	    num = 0
	    for atom in frame.atoms:
                if atom.symbol ==  symb: num += 1
            for j in range(15000 - num):
	        frame.atoms.append(XYZAtom("DOPC", -10., 0., 0.))
	    for j in range(15000 - (length - num)):
		frame.atoms.append(XYZAtom("DPPC", -10., 0., 0.))
	    atoms = sorted(frame.atoms, key=lambda w: w.symbol)
	    frame.atoms = atoms
	    #frame.atoms = []#sorted(frame.atoms, key=lambda w: w.symbol)
        i += 1

        err = (i, max(projLattice.errors), sum(projLattice.errors) / len(projLattice.errors))
        errors.append("{0} {1} {2}".format(*err))
        
        
        outFile.addFrame(frame)
 	if i > 10: break
        
    if not options.errFile is None:
        with open(options.errFile, 'w') as errFile:
            errFile.write('\n'.join(errors))
        
    outFile.save()
    if options.verbose: 
        print "Done. Execution time=%f" % (time() - startTime)    
Esempio n. 6
0
def main(argv=None):
    global options 
    options = parseCommandLine()

    xyzFile, xyzOutputFile = openFiles(options)
    frame = xyzFile.nextFrame()
    startTime = time()
    frameCounter = 0
    neighborPairs = {}
    while not frame is None:
        findNeighborPairs( frame, frameCounter, neighborPairs )
        clustered = findClusteredAtoms( neighborPairs, frameCounter, int( options.framesThr ) )
        if options.verbose: 
            delLine()
            print frameCounter,
            #l = neighborPairs.keys()
            #l.sort()
            #print "Neighbor pairs", [ (str(i) + ":" + str(neighborPairs[i])) for i in l ]
            #print  "Clusters", identifyClusters( neighborPairs, frameCounter, 1, frame ) 
            #print "Clustered atoms", findClusteredAtoms( neighborPairs, frameCounter, 1 )
        frameCounter += 1
        newFrame = XYZFrame()

        clusteredAtoms = []
        interAtoms = []
        nonClustAtoms = []
        if ( len(clustered["clustered"]) + len(clustered["interchanging"]) > 0
                ):
            print frameCounter,  ( len(clustered["clustered"]) +
                    len(clustered["interchanging"])) / float(len(frame.atoms))
        for atomInd in range( len( frame.atoms ) ):
            if atomInd in clustered['clustered']:
                clusteredAtoms.append( XYZAtom( "Clustered", *frame.atoms[atomInd].x0 ) )
            elif atomInd in clustered['interchanging']:
                interAtoms.append( XYZAtom( "Inter", *frame.atoms[atomInd].x0 ) )
            else:
                nonClustAtoms.append( XYZAtom( "NonCl", *frame.atoms[atomInd].x0 ) )
        maxNum = 0
        for i in range( maxNum - len( clusteredAtoms ) ):
            clusteredAtoms.append( XYZAtom( "Clustered", 0, 0, 0, ) )
        for i in range( maxNum - len( interAtoms ) ):
            interAtoms.append( XYZAtom( "Inter", 0, 0, 0, ) )
        for i in range( maxNum - len( nonClustAtoms ) ):
            nonClustAtoms.append( XYZAtom( "Clustered", 0, 0, 0, ) )
        newFrame.atoms = clusteredAtoms + interAtoms +  nonClustAtoms 
        xyzOutputFile.addFrame( newFrame )
        frame = xyzFile.nextFrame()
    if options.verbose:
        print "Execution time", time() - startTime
    xyzOutputFile.save()
Esempio n. 7
0
def main(argv=None):
    options = parseCommandLine()
    
    startTime = time()
    begin = int( options.begin )
    end = int( options.end )
    clearFile( options.datFilename )
    with open( options.datFilename, 'w' ) as output:
        try:
            interval = int( options.interval )
            for frameCounter in range( begin, end, interval ):
                if options.verbose: 
                    delLine()
                    print frameCounter,
                    stdout.flush()
                path = options.Filename + str( frameCounter ) + ".png" #TODO: png should be configurable
                im = Image.open( path )
                width, height = im.size
                correctionFactor = ( float( width - height ) / height )
                pixMap = im.load()
                correction = correctionFactor
                neighbors = [ ( 1, 0 ), ( 0, 1 ), ( -1, 0 ), ( 0, -1 ) ]
                allPixelsCount = 0
                similarPixelsCount = 0
                for h in range( 1, height - 1 ):
                    for w in range( 1, height - 1 ):
                        neighbor = neighbors[ randint( 0, len( neighbors ) - 1 ) ]
                        x = int( w + correction )
                        y = h
                        nX = x + neighbor[ 0 ]
                        nY = y + neighbor[ 1 ]
                        if pixMap[ x, y ] - pixMap[ nX, nY ] < 35:
                            similarPixelsCount += 1
                        allPixelsCount += 1
                    correction += correctionFactor
                fraction = float( similarPixelsCount ) / allPixelsCount
                output.write( str( frameCounter ) + " " + str( fraction )  + "\n" )
        except:
            pass
    
    if options.verbose:
        print "Execution time", time() - startTime
Esempio n. 8
0
def main():
    
    options = parseCommandLine()
    inFile = XYZFile(options.inXyzFilename)
    
    clearFile(options.outDatFilename)
    outFile = open(options.outDatFilename, 'w')
    i = 0
    startTime = time()
    omegas = []

    sumOmegas = 0L
    calc = EnergyCalculator(inFile, R, T)
    
    while True:
        i += 1
        if options.verbose:
            delLine()
            print i, 
        omega = calc.getNextEnergy(options.symbol)
        if omega is None:
            break
        omega , sim, diff = omega
        if omega > -10**4 and omega < 10**10: 
            omegas.append(omega)
            sumOmegas += omega
            outFile.write("%d  %f %f %f \n" % (i, omega, sim, diff))

        
    outFile.close()
    if options.verbose: 
        print "Done. Execution time=%f" % (time() - startTime)    
    print "omegas" ,sumOmegas, (sum(omegas))
    lenOmegas = len(omegas)
    midOmega = (sum(omegas)/len(omegas))
    print "Result omegaAB = %f" % midOmega
    sd = 0
    for omega in omegas:
        sd += (midOmega - omega)**2
    sd /= len(omegas)
    sd **= (1./2.)
    print "Standard deviation = %f" % sd
Esempio n. 9
0
def main():

    options = parseCommandLine()
    inFile = XYZFile(options.inXyzFilename)

    clearFile(options.outDatFilename)
    outFile = open(options.outDatFilename, 'w')
    i = 0
    startTime = time()
    omegas = []

    sumOmegas = 0L
    calc = EnergyCalculator(inFile, R, T)

    while True:
        i += 1
        if options.verbose:
            delLine()
            print i,
        omega = calc.getNextEnergy(options.symbol)
        if omega is None:
            break
        omega, sim, diff = omega
        if omega > -10**4 and omega < 10**10:
            omegas.append(omega)
            sumOmegas += omega
            outFile.write("%d  %f %f %f \n" % (i, omega, sim, diff))

    outFile.close()
    if options.verbose:
        print "Done. Execution time=%f" % (time() - startTime)
    print "omegas", sumOmegas, (sum(omegas))
    lenOmegas = len(omegas)
    midOmega = (sum(omegas) / len(omegas))
    print "Result omegaAB = %f" % midOmega
    sd = 0
    for omega in omegas:
        sd += (midOmega - omega)**2
    sd /= len(omegas)
    sd **= (1. / 2.)
    print "Standard deviation = %f" % sd
Esempio n. 10
0
def main():
    
    options = parseCommandLine()
    inFile = XYZFile(options.inXyzFilename)
    
    clearFile(options.outDatFilename)
    outXYZ = XYZFile(options.outDatFilename)
    i = 0
    startTime = time()
    dist = 1
    num = int(options.number)
    while True:
	frame = inFile.nextFrame()
	if i == 0:
		x, y = [], []
		for atom in frame.atoms:
			x.append(atom.x)
			y.append(atom.y)
		fieldX = ( max(x) - min(x) ) / 1.73
		fieldY = max(y) - min(y)
	newFrame = XYZFrame()
	if frame is None:
		break
	for atom in frame.atoms:
		newFrame.atoms.append(atom)
		for k in range(num):
			x0 = atom.x0
			for coord in range(len(x0)):
				x0[coord] += (random() - 0.4) * dist * 2
			newFrame.atoms.append(XYZAtom(atom.symbol, *x0))
	newFrame.comment = "%s, %s, 0.00" % (fieldX, fieldY)	
	outXYZ.addFrame(newFrame)	
        i += 1
        if options.verbose:
            delLine()
            print i, 

     
    if options.verbose: 
        print "Done. Execution time=%f" % (time() - startTime)    
Esempio n. 11
0
def main():

    options = parseCommandLine()
    inFile = XYZFile(options.inXyzFilename)

    clearFile(options.outDatFilename)
    outXYZ = XYZFile(options.outDatFilename)
    i = 0
    startTime = time()
    dist = 1
    num = int(options.number)
    while True:
        frame = inFile.nextFrame()
        if i == 0:
            x, y = [], []
            for atom in frame.atoms:
                x.append(atom.x)
                y.append(atom.y)
            fieldX = (max(x) - min(x)) / 1.73
            fieldY = max(y) - min(y)
        newFrame = XYZFrame()
        if frame is None:
            break
        for atom in frame.atoms:
            newFrame.atoms.append(atom)
            for k in range(num):
                x0 = atom.x0
                for coord in range(len(x0)):
                    x0[coord] += (random() - 0.4) * dist * 2
                newFrame.atoms.append(XYZAtom(atom.symbol, *x0))
        newFrame.comment = "%s, %s, 0.00" % (fieldX, fieldY)
        outXYZ.addFrame(newFrame)
        i += 1
        if options.verbose:
            delLine()
            print i,

    if options.verbose:
        print "Done. Execution time=%f" % (time() - startTime)
Esempio n. 12
0
def main():

    options = parseCommandLine()
    avgArea = getAvgSize(options.inXyzFilename)
    print avgArea
    lattBoxSize = ((2 * avgArea) / (3**(1 / 2.)))**(1 / 2.
                                                    )  #area of parallelogram
    print lattBoxSize
    inFile = XYZFile(options.inXyzFilename)
    latt = HexLattice(int(options.lattSize), (0, 0),
                      (lattBoxSize, lattBoxSize))

    lattProj = NearestNeighborLatticeProj(inFile, latt)
    clearFile(options.outXyzFilename)
    outFile = XYZFile(options.outXyzFilename)
    i = 0
    startTime = time()
    errors = []
    #lattProj = LatticeProjectorSimple(inFile, latt)
    while True:
        if options.verbose:
            delLine()
            if i > 0: midTime = (time() - startTime) / i
            else: midTime = 0
            print i, "Avg time per frame: ", midTime,
            sys.stdout.flush()
        projLattice = lattProj.next()
        if projLattice is None:
            break
        frame = projLattice.frame
        if options.reference:
            frame.atoms.extend(projLattice.refFrame.atoms)
            symb = "DOPC"
            length = len(frame.atoms)
            num = 0
            for atom in frame.atoms:
                if atom.symbol == symb: num += 1
            for j in range(15000 - num):
                frame.atoms.append(XYZAtom("DOPC", -10., 0., 0.))
            for j in range(15000 - (length - num)):
                frame.atoms.append(XYZAtom("DPPC", -10., 0., 0.))
            atoms = sorted(frame.atoms, key=lambda w: w.symbol)
            frame.atoms = atoms

#frame.atoms = []#sorted(frame.atoms, key=lambda w: w.symbol)
        i += 1

        err = (i, max(projLattice.errors),
               sum(projLattice.errors) / len(projLattice.errors))
        errors.append("{0} {1} {2}".format(*err))

        outFile.addFrame(frame)
        if i > 10: break

    if not options.errFile is None:
        with open(options.errFile, 'w') as errFile:
            errFile.write('\n'.join(errors))

    outFile.save()
    if options.verbose:
        print "Done. Execution time=%f" % (time() - startTime)
Esempio n. 13
0
def stdoutStep( options, i ):
    """ Outputs progress information if options.verbose is set"""
    if options.verbose:
        delLine()
        print i, 
        sys.stdout.flush()
Esempio n. 14
0
def stdoutStep(options, i):
    """ Outputs progress information if options.verbose is set"""
    if options.verbose:
        delLine()
        print i,
        sys.stdout.flush()