def check(self): """ check: Performs check whether all settings are valid. Paths and Files exist @author: chen """ from pytom.tools.files import checkFileExists, checkDirExists returnValue = checkFileExists(self.volume.getFilename()) if not returnValue: raise IOError('File: ' + str(self.volume) + ' not found!') returnValue = checkFileExists(self.reference.getReferenceFilename()) if not returnValue: raise IOError('File: ' + str(self.reference) + ' not found!') returnValue = checkFileExists(self.mask.getFilename()) if not returnValue: raise IOError('File: ' + str(self.mask) + ' not found!') returnValue = checkDirExists(self.dstDir[:-1]) if not returnValue: raise IOError('Directory: ' + str(self.dstDir) + ' not found!') return returnValue
def em2mrc(filename, target): from pytom_volume import read from pytom.tools.files import checkFileExists, checkDirExists import os if not checkFileExists(filename): raise RuntimeError('EM file not found! ', filename) if not checkDirExists(target): raise RuntimeError('Destination directory not found! ', target) emfile = read(filename) splitName = filename.split(os.sep) filename = splitName[len(splitName) - 1] ff = filename[0:len(filename) - 3] try: ff = ff.split('_') print(ff[-1]) ff = [f'sorted_{int(ff[-1])-1:02d}'] print(ff) except Exception as e: print('\n\n\n') print(e) pass ff = '_'.join(ff) newFilename = target + os.sep + ff + '.mrc' emfile.write(newFilename, 'mrc')
def readRotationsFromEMFile(self, filename, inputIsInRadians=True): """ readRotationsFromEMFile: Reads rotations from EM file and optionally converts them from radians to degrees @param filename: Name of EM file @param inputIsInRadians: @type inputIsInRadians: bool """ self._angleList = [] if not filename == '': import pytom_volume from pytom.angles.angle import rad2deg try: angs = pytom_volume.read(filename) except RuntimeError: from pytom.tools.files import checkFileExists, getPytomPath if not checkFileExists(filename): filename = getPytomPath( ) + '/angles/angleLists/' + filename angs = pytom_volume.read(filename) for i in range(angs.sizeY()): phi = angs.getV(0, i, 0) psi = angs.getV(1, i, 0) the = angs.getV(2, i, 0) if inputIsInRadians: phi = phi * rad2deg psi = psi * rad2deg the = the * rad2deg self._angleList.append([phi, psi, the])
def getVolume(self, subregion=[0,0,0,0,0,0], sampling=[0,0,0], binning=[0,0,0]): """ getVolume: Get the volume according to the given parameters.\ Note the subregion, sampling and binning parameters are not the same as \ those attributes in the class. @param subregion: subregion [startX, startY, startZ, sizeX, sizeY, sizeZ] @type subregion: list @param sampling: sampling [factorX, factorY, factorZ] @type sampling: list @param binning: binning [factorX, factorY, factorZ] @type binning: list @rtype: L{pytom_volume.vol} """ from pytom_volume import read from pytom.tools.files import checkFileExists if not checkFileExists(self._filename): raise Exception('File ' + self._filename + ' does not exist!') return read(self._filename, subregion[0], subregion[1], subregion[2], subregion[3], subregion[4], subregion[5], sampling[0], sampling[1], sampling[2], binning[0], binning[1], binning[2])
def check(self): """ check: Performs check whether all settings are valid. Paths and Files exist @author: chen """ from pytom.tools.files import checkFileExists returnValue = checkFileExists(self.result.getFilename()) if not returnValue: raise IOError(str(self.result) + ' not found!') returnValue = checkFileExists(self.orient.getFilename()) if not returnValue: raise IOError(str(self.orient) + ' not found!') return returnValue
def check(self): """ check: Performs check on self whether all settings were sane. Paths and Files exists """ from pytom.tools.files import checkFileExists, checkDirExists returnValue = checkFileExists(self.particle.getFilename()) if not returnValue: raise IOError(str(self.particle.getFilename()) + ' not found!') returnValue = returnValue and checkFileExists( self.reference.getFilename()) if not returnValue: raise IOError(str(self.reference) + ' not found!') return returnValue
def fromFile(self, filename=None): from pytom.tompy.io import read from pytom.tools.files import checkFileExists filename = filename or self._filename if checkFileExists(filename): self._weight = read(filename) else: raise RuntimeError('PeakPrior: File ' + filename + ' not found')
def run(parameters, verbose=False): """ run: Answers a http request depending on the provided parameters. Parameters can be XML=FILENAME DIR=DIRNAME @param parameters: """ from pytom.tools.files import checkDirExists, checkFileExists from pytom.frontend.serverpages.serverMessages import FileMessage, ErrorMessage if splitParameters.__class__ == list: if verbose: print(splitParameters) for i in range(len(splitParameters)): parameter = splitParameters[i] split = parameter.split('=') keyword = split[0] argument = split[1] parametersDictionary[keyword] = argument responseMessage = ErrorMessage('File not found') if 'File' in parametersDictionary: fileName = parametersDictionary['File'] if checkFileExists(fileName): responseMessage('FileExistance', fileName, 'YES') if 'Dir' in parametersDictionary: dirName = parametersDictionary['Dir'] if checkFileExists(dirName): responseMessage('DirExistance', dirName, 'YES') return str(responseMessage)
def getVolume(self): """ getVolume: Get volume of the found particle @rtype: L{pytom_volume.vol} """ from pytom_volume import read from pytom.tools.files import checkFileExists if not checkFileExists(self._filename): raise Exception('File ' + self._filename + ' does not exist!') return read(self.filename)
def __init__(self, filename='', inputIsInRadians=True, refinementParameters=None): """ ___init__: @param filename: Filename of em file storing rotations. New files must have the naming (angles_INCREMENT_NUMBERROTATIONS.em) below. Set to either one of these: angles_3_553680.em angles_07_45123.em angles_11_15192.em angles_12.85_7112.em angles_17.86_3040.em angles_18_3040.em angles_19.95_1944.em angles_25.25_980.em angles_35.76_320.em angles_38.53_256.em angles_50_100.em angles_90_26.em angles_inf_0.em @param inputIsInRadians: Are the input values in radiants (True is assumed as default) @param refinementParameters: Parameters for next refinement step @author: Thomas Hrabe """ from pytom.tools.files import checkFileExists, getPytomPath import os if checkFileExists(filename): self._filename = filename else: if os.sep in filename: #parse angle file name out of filename splitName = filename.split(os.sep) filename = splitName[-1] if not filename[-3:] == '.em': filename = filename + '.em' self._filename = getPytomPath() + '/angles/angleLists/' + filename if checkFileExists(self._filename): self.readRotationsFromEMFile(self._filename, inputIsInRadians) self._currentIndex = 0 self._refinementParameters = refinementParameters or [ self._defaultShells, self._defaultIncrement ] #shells,increment
def mrc2em(filename, target): from pytom_volume import read from pytom.tools.files import checkFileExists, checkDirExists import os if not checkFileExists(filename): raise RuntimeError('MRC file not found! ', filename) if not checkDirExists(target): raise RuntimeError('Destination directory not found! ', target) emfile = read(filename) newFilename = name_to_format(filename, target, "em") emfile.write(newFilename, 'em')
def run(parameters, verbose=False): """ run: Generate an image slice from a density file """ from pytom.tools.files import checkFileExists if verbose: print("Parsing image slice!") splitParameters = parameters.split('&') if splitParameters.__class__ == list: if verbose: print(splitParameters) for i in range(len(splitParameters)): parameter = splitParameters[i] split = parameter.split('=') keyword = split[0] argument = split[1] if verbose: print('Keyword : ', keyword) print('Arguments : ', argument) if keyword == 'File': from pytom_volume import read from pytom.tools.toImage import volumeToPNG if not checkFileExists(argument): raise IOError('File not found!') v = read(argument) if argument[len(argument) - 3:len(argument)] == '.em': pngFilename = argument[0:len(argument) - 3] + '.png' elif argument[len(argument) - 4:len(argument)] in ['.mrc']: pngFilename = argument[0:len(argument) - 4] + '.png' elif argument[len(argument) - 5:len(argument)] in ['.ccp4']: pngFilename = argument[0:len(argument) - 5] + '.png' volumeToPNG(v, pngFilename) return pngFilename
def read(file, subregion=[0, 0, 0, 0, 0, 0], sampling=[0, 0, 0], binning=[0, 0, 0]): """ read: Reads a file @param file: Path to file. Supports EM, MRC and CCP4 files @type file: str @param subregion: Specifies a subregion to be read. The first three values specify the upper left coordinates within the large volume, the last three the length of the subregion along each dimension. @type subregion: List of 6 integers @param sampling: Change read sampling. Read every second (2), third (3) pixel along each dimension. @type sampling: List of 3 integers @param binning: Bin volume along each dimension. Note, 1 will do nothing, 2 will bin with a kernelsize of 2 pixels along each dimension, 3 will bin with a kernelsize of 3 pixels along each dimension and so forth. @type binning: List of 3 integers @return: A volume object. L{pytom_volume.vol} @author: Thomas Hrabe """ from pytom.tools.files import checkFileExists from pytom_volume import read if not file.__class__ == str: raise TypeError('File parameter must be a string!') if not checkFileExists(file): raise IOError('File not found or path is wrong: ' + file) print(subregion) try: f = read(file, subregion[0], subregion[1], subregion[2], subregion[3], subregion[4], subregion[5], sampling[0], sampling[1], sampling[2], binning[0], binning[1], binning[2]) return f except RuntimeError as e: #redundant to code above, but just in case it goes through if "Wrong file format or file doesn't exist!" in e.message: raise IOError('File not found or path is wrong: ' + file) else: raise
def apply(self, volume): """ apply: Applies weighting defined in this object to value. The return value can be modified if needed. @param volume: A volume @return: self.weight * volume @author: Thomas Hrabe """ from pytom.tompy.tools import volumesSameSize from pytom.tools.files import checkFileExists if not self.isInitialized() and (not checkFileExists(self._filename)): self.initVolume(volume.sizeX(), volume.sizeY(), volume.sizeZ()) elif not self.isInitialized(): self.fromFile() assert volumesSameSize(self._weight, volume) # make sure both have same size return self._weight * volume
def mrc2ccp4(filename, target): from pytom_volume import read from pytom.tools.files import checkFileExists, checkDirExists import os if not checkFileExists(filename): raise RuntimeError('MRC file not found! ', filename) if not checkDirExists(target): raise RuntimeError('Destination directory not found! ', target) emfile = read(filename) splitName = filename.split(os.sep) filename = splitName[len(splitName) - 1] newFilename = target + os.sep + filename[0:len(filename) - 3] + '.ccp4' emfile.write(newFilename, 'ccp4')
def mrc2em(filename,destination): #from pytom_volume import read from pytom.basic.files import read from pytom.tools.files import checkFileExists,checkDirExists import os if not checkFileExists(filename): raise RuntimeError('MRC file not found! ',filename) if not checkDirExists(destination): raise RuntimeError('Destination directory not found! ', destination) emfile = read(filename) splitName = filename.split(os.sep) filename = splitName[len(splitName)-1] newFilename = destination + os.sep + filename[0:len(filename)-4] + '.em' emfile.write(newFilename,'em')
def read_em_header(filename): """ read_em_header: Reads the EM header only. @param filename: The em file @type filename: str @returns: L{pytom.basic.files.EMHeader} """ from pytom.tools.files import checkFileExists if not checkFileExists(filename): raise IOError('readEMHeader: File not found! ' + filename) f = open(filename, 'r') try: header_data = np.fromfile(f, np.dtype('int32'), 128) header = EMHeader() header.from_binary(header_data) finally: f.close() return header
def check(self): from pytom.tools.files import checkFileExists self.get_phase_flip_pl().check() self.get_ctf_conv_pl().check() if not checkFileExists(self.ctf_sqr): raise Exception('File: %s does not exist!' % self.ctf_sqr)
markerIndex = int(markerIndex) projections = ProjectionList() projectionDirectory = projectionDirectoryTemplate.replace( '_CLOSEST_', '_{:04d}_'.format(markerIndex)) alignResultFile = os.path.join(projectionDirectory, 'alignmentResults.txt') if not os.path.exists(alignResultFile): alignResultFile = '' else: alignmentResults = loadstar(alignResultFile, dtype=datatypeAR) projectionsFileNames = alignmentResults['FileName'] projectionDirectory = os.path.dirname(projectionsFileNames[0]) prefix = os.path.basename( projectionsFileNames[0]).split('_')[0] + '_' if checkFileExists(projectionList): projections.fromXMLFile(projectionList) elif checkDirExists(projectionDirectory): projections.loadDirectory(projectionDirectory, metafile=metafile, prefix=prefix) else: raise RuntimeError( 'Neither projectionList existed nor the projectionDirectory you specified! Abort' ) # transform the cropping offset if len(projections) == 0: print(markerIndex, projectionDirectory, metafile, prefix) continue
aw = 0 else: aw = float(aw) if recOffset: recOffset = [int(i) for i in recOffset.split(",")] else: recOffset = [0., 0., 0.] try: numProcesses = int(numProcesses) except: numProcesses = 0 projections = ProjectionList() if checkFileExists(projectionList): projections.fromXMLFile(projectionList) elif checkDirExists(projectionDirectory): projections.loadDirectory(projectionDirectory, metafile=metafile) else: raise RuntimeError( 'Neither projectionList existed nor the projectionDirectory you specified! Abort' ) import os if os.path.exists(os.path.join(projectionDirectory, 'alignmentResults.txt')): alignResultFile = os.path.join(projectionDirectory, 'alignmentResults.txt')
except Exception as e: print(e) sys.exit() if help is True: print(helper) sys.exit() from pytom.alignment.GLocalSampling import GLocalSamplingJob, mainAlignmentLoop from pytom.basic.structures import ParticleList, Reference, Mask, SampleInformation, PointSymmetry from pytom.score.score import FLCFScore, nxcfScore from pytom.angles.localSampling import LocalSampling from pytom.alignment.preprocessing import Preprocessing #particleList if not checkFileExists(particleList): raise RuntimeError('ParticleList file ' + particleList + ' does not exist!') pl = ParticleList() pl.fromXMLFile(particleList) if reference: if not checkFileExists(reference): raise RuntimeError('Reference file ' + reference + ' does not exist!') ref = Reference(referenceFile=reference) else: ref = Reference() if not checkFileExists(mask): raise RuntimeError('Mask file ' + mask + ' does not exist!') if isSphere: isSphere = True
if len(sys.argv) <= 2: print(helper) sys.exit() try: volume, reference, mask, wedge1, wedge2, angles, destination, band, sx, sy, sz, jobName, help = parse_script_options( sys.argv[1:], helper) except Exception as e: print(e) sys.exit() if help is True: print(helper) sys.exit() if not checkFileExists(volume): raise RuntimeError('Volume file ' + volume + ' does not exist!') if not checkFileExists(reference): raise RuntimeError('Reference file ' + reference + ' does not exist!') if not checkFileExists(mask): raise RuntimeError('Mask file ' + mask + ' does not exist!') if not checkDirExists(destination): raise RuntimeError('Destination directory ' + destination + ' does not exist!') from pytom.basic.structures import Mask, Reference, Wedge, BandPassFilter from pytom.localization.structures import Volume from pytom.angles.globalSampling import GlobalSampling
def run(parameters, verbose=False): """ run: Answers a http request depending on the provided parameters. Parameters can be XML=FILENAME DIR=DIRNAME ALIG=NAME @param parameters: """ from pytom.basic.structures import ParticleList from pytom.tools.files import checkDirExists, checkFileExists if verbose: print("Parsing particleList request!") splitParameters = parameters.split('&') if splitParameters.__class__ == list: if verbose: print(splitParameters) for i in range(len(splitParameters)): parameter = splitParameters[i] split = parameter.split('=') keyword = split[0] argument = split[1] if verbose: print('Keyword : ', keyword) print('Arguments : ', argument) if keyword == 'XML': from pytom.tools.files import readStringFile, getPytomPath import io from lxml import etree if not checkFileExists(argument): raise IOError('File not found!') pl = ParticleList('/') pl.fromXMLFile(argument) xsltString = readStringFile( getPytomPath() + '/frontend/html/xslt/ParticleList.xsl') xsltTransform = io.StringIO(xsltString) transformed = pl.xsltTransform(xsltTransform) return etree.tostring(transformed, pretty_print=True) elif keyword == 'DIR': from pytom.tools.files import checkDirExists, getPytomPath, readStringFile import io from lxml import etree if not checkDirExists(argument): raise IOError('File not found!') pl = ParticleList(argument) pl.loadDirectory() xsltString = readStringFile( getPytomPath() + '/frontend/html/xslt/ParticleList.xsl') xsltTransform = io.StringIO(xsltString) transformed = pl.xsltTransform(xsltTransform) return etree.tostring(transformed, pretty_print=True) elif keyword == 'ALIG': from pytom.tools.files import checkDirExists, getPytomPath, readStringFile import io from lxml import etree if not checkDirExists(argument): raise IOError('File not found!') pl = ParticleList(argument) pl.fromAlignmentFile(argument) xsltString = readStringFile( getPytomPath() + '/frontend/html/xslt/ParticleList.xsl') xsltTransform = io.StringIO(xsltString) transformed = pl.xsltTransform(xsltTransform) return etree.tostring(transformed, pretty_print=True) elif splitParameters.__class__ == str: if verbose: print(splitParameters)
print(helper) sys.exit() try: particleList, mask, numberClasses, endThreshold,wedge1,wedge2,symmetryN,symmetryAxisZ,symmetryAxisX,\ lowestFrequency,highestFrequency,destination,\ startTemperature,annealingStep,numberRefinementIterations,binning,\ pixelSize,diameter,jobName,help = parse_script_options(sys.argv[1:], helper) except Exception as e: print(e) sys.exit() if help is True: print(helper) sys.exit() if not checkFileExists(mask): raise RuntimeError('Mask file ' + mask + ' does not exist!') if not checkDirExists(destination): raise RuntimeError('Destination directory ' + destination + ' does not exist!') from pytom.cluster.mcoACStructures import MCOACJob,MetropolisCriterion,SigmaTemperature from pytom.basic.structures import ParticleList,Reference,Mask,Wedge,SampleInformation,PointSymmetry from pytom.score.score import FLCFScore from pytom.frontend.serverpages.createMCOACJob import createRunscripts from pytom.alignment.preprocessing import Preprocessing p = ParticleList() p.fromXMLFile(particleList) m = Mask(mask)
def run(parameters, verbose=False): """ run: Generate an image slice from a density file """ from pytom_volume import read from pytom.tools.toImage import volumeToPNG from pytom.tools.files import checkFileExists from pytom.frontend.serverpages.serverMessage import DataMessage if verbose: print("Parsing image slice!") splitParameters = parameters.split('&') if splitParameters.__class__ == list: if verbose: print(splitParameters) filename = None v = None sliceX = None sliceY = None sliceZ = None for i in range(len(splitParameters)): parameter = splitParameters[i] split = parameter.split('=') keyword = split[0] argument = split[1] if verbose: print('Keyword : ', keyword) print('Arguments : ', argument) if keyword == 'File': filename = argument if keyword == 'SliceX': sliceX = argument if keyword == 'SliceY': sliceY = argument if keyword == 'SliceZ': sliceZ = argument if not checkFileExists(filename): raise IOError('File not found!') v = read(filename) data = '' for x in range(v.sizeX()): for y in range(v.sizeX()): for z in range(v.sizeX()): data += str(v(x, y, z)) + ';' return str( DataMessage('volume', data, sizeX=str(v.sizeX), sizeY=str(v.sizeY), sizeZ=str(v.sizeZ)))
def run(parameters, verbose=False): """ run: Answers a http request depending on the provided parameters. Parameters can be XML=FILENAME DIR=DIRNAME @param parameters: """ from pytom.reconstruction.reconstructionStructures import ProjectionList from pytom.tools.files import checkDirExists, checkFileExists from pytom.frontend.serverpages.serverMessages import ErrorMessage splitParameters = parameters.split('&') if splitParameters.__class__ == list: if verbose: print(splitParameters) for i in range(len(splitParameters)): parameter = splitParameters[i] split = parameter.split('=') keyword = split[0] argument = split[1] if verbose: print('Keyword : ', keyword) print('Arguments : ', argument) if keyword == 'XML': from pytom.tools.files import readStringFile, getPytomPath import io from lxml import etree if not checkFileExists(argument): print(ErrorMessage('File / directory not found!')) return str(ErrorMessage('File / directory not found!')) pl = ProjectionList() pl.fromXMLFile(argument) xsltString = readStringFile( getPytomPath() + '/frontend/html/xslt/ProjectionList.xsl') xsltTransform = io.StringIO(xsltString) transformed = pl.xsltTransform(xsltTransform) return etree.tostring(transformed, pretty_print=True) elif keyword == 'DIR': from pytom.tools.files import checkDirExists, getPytomPath, readStringFile import io from lxml import etree if not checkDirExists(argument): print(ErrorMessage('File / directory not found!')) return str(ErrorMessage('File / directory not found!')) pl = ProjectionList() pl.loadDirectory(argument) xsltString = readStringFile( getPytomPath() + '/frontend/html/xslt/ProjectionList.xsl') xsltTransform = io.StringIO(xsltString) transformed = pl.xsltTransform(xsltTransform) return etree.tostring(transformed, pretty_print=True)
if len(sys.argv) <= 2: print(helper) sys.exit() try: particleList, mask, numberClasses, endThreshold,wedge1,wedge2,symmetryN,symmetryAxisZ,symmetryAxisX,\ lowestFrequency,highestFrequency,destination,numberIterations,binning,\ pixelSize,diameter,jobName,help = parse_script_options(sys.argv[1:], helper) except Exception as e: print(e) sys.exit() if help is True: print(helper) sys.exit() if not checkFileExists(particleList): raise RuntimeError('ParticleList file ' + particleList + ' does not exist!') if not checkFileExists(mask): raise RuntimeError('Mask file ' + mask + ' does not exist!') if not checkDirExists(destination): raise RuntimeError('Destination directory ' + destination + ' does not exist!') from pytom.cluster.mcoEXMXStructures import MCOEXMXJob from pytom.basic.structures import ParticleList, Reference, Mask, Wedge, SampleInformation, PointSymmetry from pytom.score.score import FLCFScore from pytom.frontend.serverpages.createMCOEXMXJob import createRunscripts from pytom.alignment.preprocessing import Preprocessing
def create_job_frm(): """ create job interactively - xml file will be written """ # Task 0 # particle list print( "1/10. Please enter the particle list(s) to be aligned. Multiple lists should be separated by a space." ) print("(Note the wedge situation of the particles should be set.)") print( "(It is strongly recommended that the absolute path should be given for all the particles.)" ) while True: pl_filenames = input('--> ') pl_filenames = pl_filenames.split(' ') for pl_filename in pl_filenames: if not checkFileExists(pl_filename): print("Particle list does not exist. Please enter again.") break else: break # reference print("2/10. Please enter the file name of the reference.") print("(Note it should be the same size as the particles.)") while True: ref_filename = input('--> ') if checkFileExists(ref_filename): break else: print("Reference does not exist. Please enter again.") # mask print("3/10. Please enter the file name of the mask.") print("(Note it should be the same size as the reference.)") while True: mask_filename = input('--> ') if checkFileExists(mask_filename): break else: print("Mask does not exist. Please enter again.") # starting frequency print( "4/10. Please enter the starting frequency (in pixel) of the alignment procedure." ) print("(This is equal to apply the low-pass filter to the reference.)") while True: freq = input('--> ') try: freq = int(freq) if freq > 0: break else: raise Exception() except: print( "The starting frequency should be a positive integer. Please enter again." ) # peak offset print( "5/10. Please enter the maximal distance allowed (in pixel) to shift the reference." ) print( "(This field is used to prevent shifting the volume out-of-frame and reduce the search space.)" ) while True: peak_offset = input('--> ') try: peak_offset = int(peak_offset) if peak_offset > 0: break else: raise Exception() except: print( "The peak offset should be a positive integer. Please enter again." ) # number of iterations print("6/10. Please enter the number of iterations to run.") while True: niter = input('--> ') try: niter = int(niter) if niter > 0: break else: raise Exception() except: print( "The number of iterations should be a positive integer. Please enter again." ) # binning print("7/10. Please enter the binning factor (>=1, default is 1).") while True: binning = input('--> ') try: if len(binning) == 0: binning = 1 else: binning = int(binning) if binning >= 1: break else: raise Exception() except: print( "The Binning factor should be 1 or greater. Please enter again." ) # pixel size print("8/10. Please enter the pixel size (in Angstrom).") while True: pixel_size = input('--> ') try: pixel_size = float(pixel_size) if pixel_size > 0: break else: raise Exception() except: print( "The pixel size should be a positive number. Please enter again." ) # adaptive resolution print( "9/10. Please enter the adaptive resolution to be included (in percentage, default is 0)." ) while True: adaptive_res = input('--> ') try: if len(adaptive_res) == 0: adaptive_res = 0.0 else: adaptive_res = float(adaptive_res) if adaptive_res >= 0 and adaptive_res < 1: break else: raise Exception() except: print( "The adaptive resolution should be a number in the range 0-1. Please enter again." ) # FSC criterion print("10/10. Please enter the FSC criterion to use (default is 0.5).") while True: fsc = input('--> ') try: if len(fsc) == 0: fsc = 0.5 else: fsc = float(fsc) if fsc > 0 and fsc < 1: break else: raise Exception() except: print( "The FSC criterion should be a number in the range 0-1. Please enter again." ) # write to the disk print("Finished. Save as:") while True: output = input('--> ') try: f = open(output, 'w') f.write( f"<FRMJob Destination='.' BandwidthRange='[4, 64]' Frequency='{freq:d}' MaxIterations='{niter:d}' PeakOffset='{peak_offset:d}' AdaptiveResolution='{adaptive_res:.2f}' FSC='{fsc:.2f}' binning='{binning:d}'>\n" ) #f.write(" <Reference PreWedge='' File='%s' Weighting=''>\n <ParticleList Path='/'/>\n </Reference>\n" % ref_filename) f.write( " <Reference PreWedge='' File='%s' Weighting=''>\n </Reference>\n" % ref_filename) f.write(" <Mask Filename='%s' isSphere='True'/>\n" % mask_filename) f.write( " <SampleInformation PixelSize='%.2f' ParticleDiameter='1'/>\n" % pixel_size) for pl_filename in pl_filenames: f.write(" <ParticleListLocation Path='%s'/>\n" % pl_filename) f.write("</FRMJob>") except: print( "Something is wrong during writing. Please enter again the file name." ) finally: f.close() break