示例#1
0
 def __init__(self, params):
   self.params = params
   if 'temp_file_dir' in params:
     self.tempfiledir = params.temp_file_dir
   else:
     self.tempfiledir = None
   self.tempfiles = []
   tf = self.makeTmpFile()
   self.f = open(tf.filename, 'w')
   self.pvfile = pv.File(self.f)
   #self.pvfile.write('#include "rad_def.inc"')
   self.pvfile.write('#version 3.6;')
   pv.Item("global_settings",
           assumed_gamma = params.assumed_gamma,
           ambient_light = params.ambient_color,
           #radiosity = '{Rad_Settings(Radiosity_OutdoorHQ, 1, 1)}'
           ).write(self.pvfile)
示例#2
0
def parse(inputFile, outputFile, colorMapFile):

    ############################&####
    #  OPTIONS
    ################################

    buildVoid = True

    # END OPTIONS

    ################################
    #  INITIALISE
    ################################

    parser = MCNPXParser.MCNPXParser(inputFile, outputFile, colorMapFile)
    parser.preProcess(
    )  # remove unnecessary data out of the mcnpx file (i.e. comments)

    file = povray.File(outputFile, "colors.inc", "stones.inc")
    fileImp = povray.File(outputFile + "_imp0.pov")

    ################################
    #  PARSING
    ################################

    print "START PARSING", inputFile, " to ", outputFile

    print "\nPARSING DATA CARDS"
    parser.parseDataCards()
    print "\t" + str(len(parser.dataCards)) + " DATA CARDS PARSED"

    print "\nPARSING SURFACE CARDS"
    parser.parseSurfaces()
    print "\t" + str(len(parser.surfaceCards)) + " SURFACE CARDS PARSED"

    print "\nPARSING CELL CARDS"
    parser.parseCells()
    print "\t" + str(len(parser.cellCards)) + " SURFACE CARDS PARSED"

    print "\t" + str(len(parser.universes)) + " Universes Found:",
    for uni in parser.universes:
        print str(uni) + "",
    print ""

    ################################
    #  BUILDING
    ################################

    print "\nBUILDING CELL CARDS"

    # write a standard macro for drawing universes in Pov-Ray which can be used for every sort of universe
    file.writeln("//Macro's for drawing")
    file.writeln("#macro Draw_Universe(universe, pos, rot)")
    file.indent()
    file.writeln("object {")
    file.indent()
    file.writeln("universe")
    file.writeln("#if (pos != 0)")
    file.indent()
    file.writeln("translate pos")
    file.dedent()
    file.writeln("#end")
    file.writeln("#if (rot != 0)")
    file.indent()
    file.writeln("rotate rot")
    file.dedent()
    file.writeln("#end")
    file.dedent()
    file.writeln("}")
    file.dedent()
    file.writeln("#end")

    items = []  # this list will contain all the builded cell cards
    imp0Items = []
    for i, card in (enumerate(parser.cellCards)
                    ):  # use enumerate to sort the cell cards to be builded
        cellCard = parser.getCellCard(card)
        if (cellCard and cellCard.params.has_key("IMP")):
            # cellcard with imp=0 doesn't need to be builded with colors and to the main pov-ray output file
            # it will be build without colors and a smaller scale to the fileImp output
            # this will be used to limit the rendered scene to the imp=1 space
            if (cellCard.params["IMP"] == "n=0"
                    or cellCard.params["IMP"] == "N=0"):
                povItem = parser.buildCell(cellNumber=card,
                                           parent=0,
                                           depth=0,
                                           buildVoid=buildVoid,
                                           useColor=False,
                                           scale=0.99999)
                if povItem:
                    imp0Items.append(povItem)
                continue
            else:
                povItem = parser.buildCell(cellNumber=card,
                                           parent=0,
                                           depth=0,
                                           buildVoid=buildVoid,
                                           useColor=True)
                if (povItem):
                    items.append(
                        ["//" + parser.getGeometryOfCellCard(card), povItem])
        elif (cellCard):
            povItem = parser.buildCell(cellNumber=card,
                                       parent=0,
                                       depth=0,
                                       buildVoid=buildVoid,
                                       useColor=True)
            if (povItem):
                items.append(
                    ["//" + parser.getGeometryOfCellCard(card), povItem])

    imp0Cells = parser.getImpZeroCellCard()
    imp0Items = []
    if (imp0Cells):
        for cell in imp0Cells:
            povItem = parser.buildCell(cellNumber=cell.number,
                                       parent=0,
                                       depth=0,
                                       buildVoid=buildVoid,
                                       useColor=False,
                                       scale=0.99999)
            if povItem:
                imp0Items.append(povItem)
        if (len(imp0Items) == 1):
            fileImp.write(imp0Items[0])
        elif (len(imp0Items) > 1):
            fileImp.writeln("union {")
            fileImp.indent()
            for item in imp0Items:
                fileImp.write(item)
            fileImp.dedent()
            fileImp.writeln(" }")

    # write the declared macro's for the universes to the povray file
    # it needs a correct sorting so every sub macro that is used in a universe is known
    # every universe is defined with a certain depth (depth first added to the pov ray file)
    file.writeln("// DECLARED UNIVERSES")
    file.writeln(
        "// ***************************************************************************"
    )
    sortedUniverses = sorted(parser.declaredUniverses,
                             key=lambda depth: depth[0],
                             reverse=True)
    for i in range(0, len(sortedUniverses)):
        file.writeln("// UNIVERSE " + parser.declaredUniverses[i][1])
        file.write(parser.declaredUniverses[i][2])

    # After printing all the macro's, the cell cards are added to the file
    file.writeln("// All cells are combined in a big union")
    file.writeln("union {")
    file.indent()
    for i in range(0, len(items)):
        file.writeln(items[i][0])
        file.write(items[i][1])
    file.dedent()
    file.writeln("}")
    file.writeln("")

    # print surface cards to the povray output as debug information
    file.writeln("// LIST OF ALL SURFACES:")
    for card in parser.surfaceCards:
        surfaceCard = parser.surfaceCards[card]
        file.writeln("//" + surfaceCard.getSurfaceLine())

    print "\t" + str(len(parser.cellCards)) + " CELL CARDS BUILDED"
    print "\nEND BUILDING CELL CARDS"

    print "\nMCNPX to POV RAY COMPLETED"
    print "TITLE MCNPX: " + parser.title

    #oStrippedFile = open(inputFile + "stripped.txt", 'w')
    #for line in parser.cellBlock:
    #	oStrippedFile.writelines(line + '\n')
    #oStrippedFile.writelines('\n')
    #for line in parser.surfaceBlock:
    #	oStrippedFile.write(line + '\n')

    parser.close()
示例#3
0
def parse(inputFile, surfacesFile, cellsFile, universesFile, importanceFile,
          materialsFile, cellTreeFile):

    ############################&####
    #  OPTIONS
    ################################

    # buildVoid = True

    # END OPTIONS

    ################################
    #  INITIALISE
    ################################
    parser = MCNPXParser.MCNPXParser(inputFile, surfacesFile)
    parser.preProcess(
    )  # remove unnecessary data out of the mcnpx file (i.e. comments)

    fileSurfaces = povray.File(surfacesFile)
    fileCells = povray.File(cellsFile)
    fileUniverses = povray.File(universesFile)
    fileImportance = povray.File(importanceFile)
    fileMaterials = povray.File(materialsFile)
    fileCellTree = povray.File(cellTreeFile)

    ################################
    #  PARSING
    ################################
    print "\nSTART PREPARSING", inputFile

    print "\nPREPARSING DATACARDS"
    parser.parseDataCards()
    print "\t" + str(len(parser.dataCards)) + " DATA CARDS PARSED"

    # write all materials defined in the mcnpx data block to fileMaterials
    # including the optional name for the material
    print parser.materialCards
    for mat in parser.materialCards.keys():
        fileMaterials.writeln(
            str(mat) + " " + str(parser.materialCardsName[int(mat)]))

    print "\nPREPARSING SURFACE CARDS"
    parser.parseSurfaces()
    print "\t" + str(len(parser.surfaceCards)) + " SURFACE CARDS PARSED"
    for surface in parser.surfaceCards:
        fileSurfaces.writeln(
            str(surface) + "&" + str(parser.surfaceCards[surface].mnemonic) +
            "&" + str(parser.surfaceCards[surface].data))

    print "\nPREPARSING CELL CARDS"
    parser.parseCells()

    # write the cellcard with importance 0 to fileImportance
    imp0 = parser.getImpZeroCellCard()
    if (imp0):
        for cCard in imp0:
            if (cCard):
                parser.writeOuterCaseToFile(cCard, fileImportance)
    for cell in parser.cellCards:
        fileCells.writeln(
            str(cell) + "&" + str(parser.cellCards[cell].material) + "&" +
            str(parser.cellCards[cell].d) + "&" +
            str(parser.cellCards[cell].geometry) + "&" +
            str(parser.cellCards[cell].params))

    # write all universes defined in the mcnpx file to fileUniverses
    for uni in parser.universes:
        uniLine = uni
        for uniCell in parser.universes[uni]:
            uniLine = uniLine + "&" + str(uniCell)
        fileUniverses.writeln(uniLine)

    print "\t" + str(len(parser.cellCards)) + " CELL CARDS PARSED"

    # write the tree structure of the cells and universes to file
    fileCellTree.writeln(parser.createCellTree())

    print "\nPREPARSING COMPLETED"

    print "TITLE MCNPX: " + parser.title

    parser.close()
示例#4
0
parser.add_option('--mode', type='int', action='store', default=1)

(options, args) = parser.parse_args()

if len(sys.argv) == 1:
    # user has given no arguments: print help and exit
    print parser.format_help().strip()
    sys.exit()

#-------------------------------------------------------------------------------

nr_atoms = gaussian.get_nr_atoms(options.chk)
atom_xyz = gaussian.get_atom_coordinates(options.chk, nr_atoms)
bonds = gaussian.get_bonds(options.chk, nr_atoms)

file = povray.File(options.output, 'colors.inc')

#location = (15, 20, 0)
location = (0, 0, -15)  #nm 134
location = (0, 5, 10)  #mto

molecule_povray.setup_scenery(location, location, file)

molecule_povray.draw_molecule(atom_xyz, bonds, 'Gray', file)

freq, I, reduced_mass, C, dipole_derv = ir.vibrational_analysis(options.chk)

for i in range(len(C[options.mode - 1])):
    if numpy.dot(C[options.mode - 1][i], C[options.mode - 1][i]) > 0.1:
        molecule_povray.draw_vector(atom_xyz[i], C[options.mode - 1][i],
                                    'Green', 2.0, file)
示例#5
0
def parse(inputFile, outputFile, cellFile, colorMapFile):
    
############################&####
#  OPTIONS
################################
    
    buildVoid = True
    
# END OPTIONS

################################
#  INITIALISE
################################    
  
    parser = MCNPXParser.MCNPXParser(inputFile, outputFile, colorMapFile)
    parser.preProcess() # remove unnecessary data out of the mcnpx file (i.e. comments)
    
    file=povray.File(outputFile,"colors.inc","stones.inc")#, "camera.pov","lights.pov")

################################
#  PARSING
################################
    print "START PARSING", inputFile, " to ", outputFile
    
    print "PARSING DATA CARDS"
    parser.parseDataCards()
    print "\t" + str(len(parser.dataCards)) + " DATA CARDS PARSED"
    
    print "PARSING SURFACE CARDS"
    parser.parseSurfaces()
    print "\t" + str(len(parser.surfaceCards)) + " SURFACE CARDS PARSED"

    print "PARSING CELL CARDS"
    parser.parseCells()
    
    print "\tUniverses Found:",
    for uni in parser.universes:
        print str(uni) + "",
    print ""

################################
#  BUILDING
################################
    print "BUILD CELL CARDS"
    
    # write a standard macro for drawing universes in Pov-Ray which can be used for every sort of universe
    file.writeln("//Macro's for drawing")
    file.writeln("#macro Draw_Universe(universe, pos, rot)")
    file.indent()
    file.writeln("object {")
    file.indent()
    file.writeln("universe")
    file.writeln("#if (pos != 0)")
    file.indent()
    file.writeln("translate pos")
    file.dedent()
    file.writeln("#end")
    file.writeln("#if (rot != 0)")
    file.indent()
    file.writeln("rotate rot")
    file.dedent()
    file.writeln("#end")
    file.dedent()    
    file.writeln("}")
    file.dedent()
    file.writeln("#end")

  
    items = [] # this list will contain all the builded cell cards
    cellF = open(cellFile, 'r+')
    for line in cellF:
        if (line != ""):
            povItem = parser.buildCell(cellNumber = int(line), parent = -1, depth = 0,  buildVoid = buildVoid, useColor=True)
            if (povItem):
                items.append(["//" + parser.getGeometryOfCellCard(line), povItem])

    # write the declared macro's for the universes to the povray file
    # it needs a correct sorting so every sub macro that is used in a universe is known
    # every universe is defined with a certain depth (depth first added to the pov ray file)
    file.writeln("// DECLARED UNIVERSES")
    file.writeln("// ***************************************************************************")
    sortedUniverses = sorted(parser.declaredUniverses, key=lambda depth: depth[0], reverse=True)
    for i in range(0, len(sortedUniverses)): 
        file.writeln("// UNIVERSE " + parser.declaredUniverses[i][1])
        file.write(parser.declaredUniverses[i][2])
        
    # After printing all the macro's, the cell cards are added to the file
    file.writeln("//All cells are combined in a big union")
    file.writeln("union {")
    file.indent()    
    for i in range(0,len(items)):
        file.writeln(items[i][0])
        file.write(items[i][1]) 
    file.dedent()
    file.writeln("}")
    file.writeln("")

    # print surface cards to the povray output as debug information
    file.writeln("// LIST OF ALL SURFACES:")
    for card in parser.surfaceCards:
        surfaceCard = parser.surfaceCards[card]
        file.writeln("//" + surfaceCard.getSurfaceLine())

    
    print "\t" + str(len(items)) + " CELL CARDS BUILDED"
    print "\nEND BUILDING CELL CARDS"

    print "\nMCNPX to POV RAY COMPLETED"
    print "TITLE MCNPX: " + parser.title

    #oStrippedFile = open(inputFile + "stripped.txt", 'w')
    #for line in parser.cellBlock:
    #    oStrippedFile.writelines(line + '\n')
    #oStrippedFile.writelines('\n')
    #for line in parser.surfaceBlock:
    #    oStrippedFile.write(line + '\n')

    parser.close()