Example #1
0
def main(argv=None):

    options = parseCommandLine()

    #===========================================================================
    # opening files and so on
    #===========================================================================
    try:
        model = Model().read(options.groFilename)
        fp = openXTC(options.xtcFilename)
        clearFile(options.xyzFilename)
        xyzFile = XYZFile(options.xyzFilename)
    except:
        raise (InputError(options.xyzFilename,
                          "error while opening gro, xtc or xyz file"))

    if not options.ndxFilename is None:
        try:
            ndxFile = IndexFile(fname=options.ndxFilename)
        except:
            raise (InputError("error while opening ndx file"))

        atomsIndexes = []
        for (_, atomList) in ndxFile.dic.items():
            atomsIndexes += atomList
    else:
        atomsIndexes = range(1, len(model.atoms) + 1)

    createXYZFile(fp, model, atomsIndexes, xyzFile, options)
Example #2
0
def main(argv = None):
    
    options = parseCommandLine()

    #===========================================================================
    # opening files and so on
    #===========================================================================  
    try:
        model = Model().read(options.groFilename)
        fp = openXTC(options.xtcFilename)
        clearFile(options.xyzFilename)
        xyzFile = XYZFile(options.xyzFilename)
    except:
        raise(InputError(options.xyzFilename, "error while opening gro, xtc or xyz file"))
    
    if not options.ndxFilename is None:
        try:
            ndxFile = IndexFile(fname = options.ndxFilename)
        except:
            raise(InputError("error while opening ndx file"))
        
        atomsIndexes = []
        for (_, atomList) in ndxFile.dic.items():
            atomsIndexes += atomList
    else:
        atomsIndexes = range(1, len(model.atoms) + 1)
        
    createXYZFile(fp, model, atomsIndexes, xyzFile, options)
Example #3
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)    
Example #4
0
def main():
    options = parseCommandLine()
    symbols, atomNum = identifyAtomTypes(options.inXyzFilename, options)
    print symbols
    inFile = XYZFile(options.inXyzFilename)
    clearFile(options.outPngFileTemp)
    i = 0
    startTime = time()

    frame = inFile.nextFrame()

    colours = [
        (255, 255, 255)  #white
        ,
        (150, 150, 150)  # grey
        ,
        (0, 0, 0)  # black
        ,
        (150, 0, 0)  # blue
        ,
        (0, 150, 0)  # green
    ]
    sizeX, sizeY = 500, 500
    countX, countY = 100, 100
    while not frame is None:
        stdoutStep(options, i)
        i += 1

        #prepare image
        im = Image.new("RGBA", (countX, countY))
        pix = im.load()

        rescaleFrameToImage(frame, countX, countY)
        for coords in product(range(countX), range(countY)):
            pix[coords[0], coords[1]] = colours[symbols.index(
                findClosestAtom(frame, coords))]
            #print findClosestAtom( frame, coords), coords
        #for atom in frame.atoms:
        #    print atom.x, atom.y
        #    pix[ int( atom.x ), int( atom.y )] = colours[-1]

        im = im.resize((sizeX, sizeY), Image.ANTIALIAS)
        im = im.transpose(Image.FLIP_TOP_BOTTOM)
        #im.show()
        im.save(options.outPngFileTemp + str(i) + ".png")
        frame = inFile.nextFrame()

    if options.verbose:
        print "Done. Execution time=%f" % (time() - startTime)
Example #5
0
def main():
    options = parseCommandLine()
    symbols, atomNum = identifyAtomTypes( options.inXyzFilename, options )
    print symbols 
    inFile = XYZFile( options.inXyzFilename )
    clearFile( options.outPngFileTemp )
    i = 0
    startTime = time()
    
    frame = inFile.nextFrame()

    colours = [ 
            ( 255, 255, 255 ) #white
            , ( 150, 150, 150 ) # grey
            , ( 0, 0, 0 ) # black
            , ( 150, 0, 0) # blue
            , ( 0, 150, 0 ) # green
            ]
    sizeX, sizeY = 500, 500
    countX, countY = 100, 100
    while not frame is None:
        stdoutStep( options, i )
        i += 1

        #prepare image
        im = Image.new( "RGBA", ( countX, countY ) )
        pix = im.load()
        
        rescaleFrameToImage( frame, countX, countY )
        for coords in product( range( countX ), range( countY ) ):
            pix[coords[0], coords[1]] =  colours[symbols.index( findClosestAtom( frame,
                coords ) )]
            #print findClosestAtom( frame, coords), coords
        #for atom in frame.atoms:
        #    print atom.x, atom.y
        #    pix[ int( atom.x ), int( atom.y )] = colours[-1]

        im = im.resize( ( sizeX, sizeY ), Image.ANTIALIAS )
        im = im.transpose( Image.FLIP_TOP_BOTTOM )
        #im.show()
        im.save( options.outPngFileTemp + str(i) + ".png" )
        frame = inFile.nextFrame()
        
        
    
    if options.verbose: 
        print "Done. Execution time=%f" % (time() - startTime)    
Example #6
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
Example #7
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
Example #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
Example #9
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)    
Example #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)
Example #11
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)
Example #12
0
def openFiles(options):
    xyzFile = XYZFile(options.xyzFilename)
    clearFile( options.xyzOutput )
    outFile = XYZFile( options.xyzOutput )
    return xyzFile, outFile