def load_fields_3D(file,field_id): coords, fields = io.ReadDatFile(infile) nfields = fields.shape[-1] if field_id>nfields: print('Warning No Field!') else: singlefield = fields[:,:,:,field_id] return coords,fields,singlefield
zeropadded=str("{val:0>{width}}".format(val=outfile_digits,width=maxdigit)) outfile = outfile_notdigits + zeropadded + ".vtk" # check if vtk dont already exist? # IMPLEMENT ME if args.verbose: logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) else: logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.WARNING) orthorhombic = True # Check whether the input file exits, and whether it is a binary PolyFTS file or a formatted on. # Dispatch reading to relevant function. # Open as binary first print("Reading input file {}".format(infile)) # if iotools.TestBinFile(infile): #ndim, Nx, orthorhombic, M, nfields, AllCoords, AllFields = iotools.ReadBinFile(infile) # AllCoords, AllFields = iotools.ReadBinFile(infile) # else: #ndim, Nx, orthorhombic, M, nfields, AllCoords, AllFields = iotools.ReadDatFile(infile) AllCoords, AllFields = iotools.ReadDatFile(infile) logging.info("Orthorhombic cell? {}".format(orthorhombic)) print ("Outputting to Legacy VTK formatted file {}".format(outfile)) #viztools.writeVTK(outfile, Nx, orthorhombic, M, AllCoords, AllFields) viztools.writeVTK(outfile, AllCoords, AllFields)
default='epsilon.h5', type=str, help='Output h5 file to be read by MPB code') # Parse the command-line arguments args = parser.parse_args() # setup and parse input file name # use iotools to load density.bin to get coords and fields if args.input != '': infile = args.input suffix = infile.split('.')[-1] if suffix == 'bin': coords, fields = io.ReadBinFile(infile) fields_have_imag = True elif suffix == 'dat': coords, fields = io.ReadDatFile(infile) fields_have_imag = False else: raise RuntimeError(f"invalid suffix of args.input: {suffix}") else: # args.input not specified, try density.bin and density.dat if os.path.isfile('density.bin'): coords, fields = io.ReadBinFile('density.bin') fields_have_imag = True elif os.path.isfile('density.dat'): coords, fields = io.ReadDatFile('density.dat') fields_have_imag = False else: raise RuntimeError( "Default inputs density.bin and density.dat not found")
if newDim == 3: Nz = args.Nz # number of plane waves in new dimension Lz = args.Lz # length of box in new dimension infiletype = infilename.split('.')[-1] outfiletype = outfilename.split('.')[-1] if (infiletype != "bin" and infiletype != 'dat'): raise RuntimeError( f"input file ({infilename}) must have file type of .bin or .dat") if (outfiletype != "bin" and outfiletype != 'dat' and outfiletype != 'in'): raise RuntimeError( f"output file ({outfilename}) must have file type of .bin, .dat or .in" ) if infiletype == 'dat': coords, fields = io.ReadDatFile(infilename) else: coords, fields = io.ReadBinFile(infilename) #cb, fb = io.ReadBinFile('density.bin') #cd, fd = io.ReadDatFile('density.dat') #pdb.set_trace() # check newDim relative to origDim origDim = len(coords.shape) - 1 assert (origDim < newDim), "output dimension must be greater than input dimension" if origDim == 1: # convert from 1d to 2d
#in order to change this expand the box by a factor, so the relative #tolerance is tighter box_multiplier = 0.5 / args.tolerance # if not os.path.isfile('structure.cif') and not args.overwrite: # make_domains(args.filename) # else: # print('Found an existing structure.cif skipping domain calculation, disable this feature with -o') #====================================================================== #this section finds the domains, using domaintools with meshing enabled #====================================================================== filetype = re.split('\.', args.filename)[-1] if filetype == 'bin': AllCoords, AllFields = io.ReadBinFile(args.filename) elif filetype == 'dat': AllCoords, AllFields = io.ReadDatFile(args.filename) else: raise NotImplementedError('This only supports .bin and .dat files') #normalize by box length #extra AllCoords[1,1,1] is because boxes are mesured by lower left corner box_length = AllCoords[-1, -1, -1] + AllCoords[1, 1, 1] AllCoords = AllCoords / (box_length) domainanalyzer = DomainAnalyzer(AllCoords, AllFields) ndomains, com, area, vol, IQ = domainanalyzer.getDomainStats( plotMesh=False, add_periodic_domains=True) domainanalyzer.meshAllDomains(plotfile="mesh_all.png") stats = np.vstack((com.T, area, vol, IQ)).T np.savetxt("stats_mesh.dat", stats, header="comx comy comz area vol IQ") #====================================================================== #this section makes a crystalography file for platon (.cif)