def toHTMLFile(self,filename): """ toHTMLFile: Overrides parent method and stores CorrelationMatrixJob to HMTL @param filename: HTML filename """ from lxml import etree import io from pytom.tools.files import getPytomPath,readStringFile pytomPath = getPytomPath() xsltString = readStringFile(pytomPath + '/xslt/CorrelationMatrix.xsl') xsltStringIO = io.StringIO(xsltString) selfHTML = self.xsltTransform(xsltStringIO) htmlString = etree.tostring(selfHTML,pretty_print=True) file = open(filename, "w") file.write(htmlString) file.close()
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 createRunscripts(filename, jobFile): """ createRunscripts: """ from pytom.tools.files import dump2TextFile, getPytomPath text = '#!/bin/bash\n' text += 'pytom ' + getPytomPath() + '/bin/mcoEXMX.py -j ' + jobFile + '\n' dump2TextFile(filename, text, append=False)
def createRunscripts(filename,parameters): """ createRunscripts: """ from pytom.tools.files import dump2TextFile,getPytomPath text = '#!/bin/bash\n' text += 'pytom ' + getPytomPath() + '/bin/reconstructWB.py ' + parameters dump2TextFile(filename, text,append = False)
def createRunscripts(filename, jobFile, x, y, z): """ createRunscripts: """ from pytom.tools.files import dump2TextFile, getPytomPath text = '#!/bin/bash\n' text += 'pytom ' + getPytomPath( ) + '/bin/localization.py ' + jobFile + ' %d %d %d' % (x, y, z) + '\n' dump2TextFile(filename, text, append=False)
def showRotations(self,volume,directory,mask=None): """ showRotations: Will store x,y,z slice through volume after each rotation was applied """ from pytom.tools.toImage import volumeToPNG from pytom.tools.files import dump2TextFile from pytom_volume import vol,rotateSpline from pytom.tools.files import getPytomPath,readStringFile from pytom.frontend.htmlDefines import headResponse200,copyright pytomPath = getPytomPath() cssDefines = readStringFile(pytomPath + '/frontend/htmlDefines/CSS.css') html = '<html>' + cssDefines html = html + '\n<title>PyTom Alignment</title>\n' html = html + '<body><center><h1 type="Main">List of Rotations</h1></center>\n' html = html + '</br></br></br></br></br></br></br></br><center>\n' html = html + '<table>\n' html = html + '<tr><td>Z1 (Phi) Z2 (Psi) X(Theta)</td><td>x-Slice</td><td>y-Slice</td><td>z-Slice</td></tr>' rotated = vol(volume.sizeX(),volume.sizeY(),volume.sizeZ()) if not mask: mask = vol(volume.sizeX(),volume.sizeY(),volume.sizeZ()) mask.setAll(1) volume = volume * mask self.reset() rotation = self.nextRotation() rotationCounter = 0 while not rotation == [None,None,None]: rotateSpline(volume,rotated,rotation[0],rotation[1],rotation[2]) html = html + '<tr><td>' + str(rotation[0]) + ' ' + str(rotation[1]) + ' ' + str(rotation[2]) +'</td>/n' volumeToPNG(rotated,directory + str(rotationCounter) + '-x.png',rotated.sizeX()/2,'x') html = html + '<td><img src="' + directory + str(rotationCounter) + '-x.png"/></td>' volumeToPNG(rotated,directory + str(rotationCounter) + '-y.png',rotated.sizeY()/2,'y') html = html + '<td><img src="' + directory + str(rotationCounter) + '-y.png"/></td>' volumeToPNG(rotated,directory + str(rotationCounter) + '-z.png',rotated.sizeZ()/2,'z') html = html + '<td><img src="' + directory + str(rotationCounter) + '-z.png"/></td>' rotation = self.nextRotation() rotationCounter = rotationCounter + 1 html = html + '</body></html>' dump2TextFile(directory + 'rotations.html',html)
def run(parameters, verbose=True): """ run: Determines Path / URL to documentation files """ from pytom.tools.files import getPytomPath pytomPath = getPytomPath() apiDocPath = pytomPath + '/doc/index.html' if verbose: print('API DOC PATH : ', apiDocPath) return apiDocPath
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 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)
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)