def getJavaIJappCmd(memory, appName, args, batchMode=False): '''Launch an Java application based on ImageJ ''' from protlib_filesystem import getXmippPath if len(memory) == 0: memory = "2g" print "No memory size provided. Using default: " + memory imagej_home = getXmippPath("external", "imagej") lib = getXmippPath("lib") javaLib = getXmippPath('java', 'lib') plugins_dir = os.path.join(imagej_home, "plugins") arch = getArchitecture() cmd = "java -Xmx%(memory)s -d%(arch)s -Djava.library.path=%(lib)s -Dplugins.dir=%(plugins_dir)s -cp %(imagej_home)s/*:%(javaLib)s/* %(appName)s %(args)s" % locals() if batchMode: cmd += " &" return cmd
def getXmippLabels(): ''' Parse the labels definition from the 'libraries/data/metadata_label.h' file ''' labelHeader = getXmippPath(os.path.join('libraries', 'data', 'metadata_label.h')) f = open(labelHeader) labels = [] comments = {} labelsPrefixes = ['MDL_', 'RLN_', 'BSOFT_'] for line in f: line = line.strip() for prefix in labelsPrefixes: if line.startswith(prefix) and '///<' in line: parts = line.split('///<') mdl = parts[0].strip()[:-1] # remove last comma comm = parts[1].strip() comments[mdl] = comm if line.startswith('MDL::addLabel(' + prefix): l = line.find('(') r = line.find(')') parts = line[l + 1:r].split(',') label = {} label['name'] = parts[2].replace('"', '').strip() label['type'] = parts[1].strip() label['enum'] = parts[0].strip() label['comment'] = comments.get(label['enum'], "") labels.append(label) return labels
def createPanels(self): root = self.master root.columnconfigure(0, minsize=100, weight=1) root.columnconfigure(1, minsize=360, weight=4) root.rowconfigure(0, weight=1) registerCommonFonts() #left panel bgColor = 'white' leftFrame = tk.Frame(root, bg=bgColor) leftFrame.columnconfigure(0, weight=1) leftFrame.rowconfigure(0, minsize=100) imgPath = getXmippPath('resources', 'xmipp_logo.gif') self.img = tk.PhotoImage(file=imgPath) tk.Label(leftFrame, image=self.img, bg=bgColor).grid(column=0, row=0, sticky='we') tk.Label(leftFrame, text='Xmipp '+ getXmippVersion(), font=Fonts['button'], bg=bgColor).grid(column=0, row=1, sticky='we') # TODO: insert revision extracting it from git repository # tk.Label(leftFrame, text='r12.4.3.11834', bg=bgColor).grid(column=0, row=2, sticky='we') leftFrame.grid(column=0, row=0, sticky='nsew', padx=5, pady=5, rowspan=2) self.grid(column=1, row=0, sticky='nsew', padx=5, pady=5) self.nb = ttk.Notebook(self.master) self.nb.grid(row=0, column=1, sticky='nsew', padx=5, pady=5) self.addTab("About", "README") self.addTab("Authors", "AUTHORS", getAuthorLine) self.addTab("Software", "SOFTWARE") self.addTab("License", "COPYING") self.btn = XmippButton(self.master, text='Close') self.btn.grid(row=1, column=1, sticky='se', padx=5, pady=5) self.btn.config(command=self.close) self.btn.bind('<Return>', func=self.close) self.btn.focus_set()
def createImageButton(parent, text, image, cmd): try: helpImage = PhotoImage(file = getXmippPath(os.path.join("resources", image))) btn = Button(parent, image=helpImage, command=cmd, bd=0) btn.image = helpImage; except TclError: btn = Button(parent, text=text, bg="#a7dce1", activebackground="#72b9bf", command=cmd) return btn
def getImageJPluginCmd(memory, macro, args, batchMode=False): from protlib_filesystem import getXmippPath if len(memory) == 0: memory = "1g" print "No memory size provided. Using default: " + memory imagej_home = getXmippPath("external/imagej") plugins_dir = os.path.join(imagej_home, "plugins") macro = os.path.join(imagej_home, "macros", macro) imagej_jar = os.path.join(imagej_home, "ij.jar") cmd = """ java -Xmx%s -Dplugins.dir=%s -jar %s -macro %s "%s" """ % (memory, plugins_dir, imagej_jar, macro, args) if batchMode: cmd += " &" return cmd
def run(self): fn = self.getParam("-i") from os.path import splitext [fnBase, ext] = splitext(fn) if ext != ".cpp": reportError(fn + " is not a .cpp file") command = "g++ " if self.checkParam("--debug"): command += "-g -pg" xmippDir = getXmippPath() if xmippDir == "": reportError("$XMIPP_HOME is not set in the environment") scipionDir = os.environ["SCIPION_HOME"] command += ( " -o " + fnBase + " " + fn + " -O -D_LINUX " + "-L" + xmippDir + "/lib " + "-I" + xmippDir + "/libraries " + "-I" + xmippDir + " " + "-lXmippClassif -lXmippData -lXmippInterface -lXmippRecons -lXmippDimred -lXmippBilib -lfftw3 -lfftw3_threads -lsqlite3 -ltiff -ljpeg" ) command += ( " -I" + xmippDir + "/external/python/Python-2.7.2/Include -I" + xmippDir + "/external/python/Python-2.7.2 -L" + xmippDir + "/external/python/Python-2.7.2 -lpython2.7 -I" + xmippDir + "/lib/python2.7/site-packages/numpy/core/include" + " -I" + xmippDir + "/external" + " -I" + scipionDir + "/software/include -L" + scipionDir + "/software/lib" ) os.system(command)
def addTab(self, text, file, processLine=None): tab = tk.Frame(self.nb) self.nb.add(tab, text=text) self.tabs[text] = tab txt = TaggedText(tab, width=60, height=20, bg='lightgray'); txt.frame.grid(column=0, row=0, sticky='nsew', padx=10, pady=10) f = open(getXmippPath(file)) for line in f: if processLine: line = processLine(line) if line: txt.addLine(line) f.close() txt.setReadOnly(True) return txt
def setUp(self): """This function performs all the setup stuff. """ os.environ['PROTOCOL_SCRIPT'] = sys.argv[0] #run this at xmipp level # Asume 'xmipp' and 'testXmipp' are at the same level curdir = os.path.dirname(getXmippPath()) self.ProjectDir = join(curdir, 'testXmipp/input/Protocol_Projection_Matching') self.WorkingDir = 'ProjMatch/new20' self.goldWorkingDir = 'ProjMatch/goldStandard' self.path = join(self.ProjectDir,self.WorkingDir) tmpPath = join(self.path, 'tmp') mkpath(tmpPath, 0777, True) os.chdir(self.ProjectDir) print "Changed directory to", self.ProjectDir self.log = XmippLog(join(tmpPath, 'projmatch.log')) self.src = 'ProjMatch/goldStandard/' self.dst = 'ProjMatch/new20/'
def getXmippLabelsName(): ''' Parse the labels name from the 'libraries/data/metadata_label.h' file ''' labelHeader = getXmippPath(os.path.join('libraries', 'data', 'metadata_label.h')) f = open(labelHeader) labels = [] comments = {} for line in f: line = line.strip() if line.startswith('MDL_') and '///<' in line: parts = line.split('///<') mdl = parts[0].strip()[:-1] # remove last comma comm = parts[1].strip() comments[mdl] = comm if line.startswith('MDL::addLabel(MDL_'): l = line.find('(') r = line.find(')') parts = line[l + 1:r].split(',') labels.append(parts[2].replace('"', '').strip()) return labels
def validate(self): errors = [] fnShAlignment=getXmippPath('lib/python2.7/site-packages/sh_alignment') if not os.path.exists(fnShAlignment) and self.AlignmentMethod=="Fast Fourier": errors.append("Fast Fourier can only be used if Xmipp has been installed with FRM support") return errors
class TestEMX(unittest.TestCase): testsPath = getXmippPath("resources", "test") def setUp(self): """This function performs all the setup stuff. """ os.chdir(self.testsPath) def test_00emxMicrograph(self): """ Create micrograph and play a little with it """ m1 = EmxMicrograph('mic', 1) m1.set('acceleratingVoltage', 100) m1.set('defocusU', 1000.) m1.set('pixelSpacing__X', 5.6) m1.set('pixelSpacing__Y', 5.7) #reference dictPrimaryKeys = collections.OrderedDict([('fileName', 'mic'), ('index', 1)]) dictAttributes = collections.OrderedDict([('acceleratingVoltage', 100), ('defocusU', 1000.0), ('pixelSpacing__X', 5.6), ('pixelSpacing__Y', 5.7)]) self.assertEqual(m1.dictPrimaryKeys, dictPrimaryKeys) self.assertEqual(m1.dictAttributes, dictAttributes) def test_10emxParticle(self): """ Create a particle and play a little with it """ m1 = EmxMicrograph('mic', 1) m1.set('acceleratingVoltage', 100) m1.set('defocusU', 1000.) m1.set('pixelSpacing__X', 5.6) m1.set('pixelSpacing__Y', 5.7) p1 = EmxParticle('part', 1) p1.set('defocusU', 1000.10) p1.set('pixelSpacing__X', 5.66) p1.set('pixelSpacing__Y', 5.77) p1.setMicrograph(m1) #reference dictPrimaryKeys = collections.OrderedDict([('fileName', 'part'), ('index', 1)]) dictAttributes = collections.OrderedDict([('defocusU', 1000.1), ('pixelSpacing__X', 5.66), ('pixelSpacing__Y', 5.77)]) dictForeignKeys = collections.OrderedDict([('fileName', 'mic'), ('index', 1)]) #dictForeignKeys self.assertEqual(p1.dictPrimaryKeys, dictPrimaryKeys) self.assertEqual(p1.dictAttributes, dictAttributes) self.assertEqual(p1.dictForeignKeys[MICROGRAPH].dictPrimaryKeys, dictForeignKeys) def test_20clear(self): """Test clear function """ m1 = EmxMicrograph('mic', 1) m1.set('acceleratingVoltage', 100) m1.set('defocusU', 1000.) m1.set('pixelSpacing__X', 5.6) m1.set('pixelSpacing__Y', 5.27) m1.clear() m2 = EmxMicrograph('mic', 1) m2.set('activeFlag', None) self.assertEqual(m1, m2) self.assertFalse(m1.strongEq(m2)) def test_30read(self): #fileName = "massive_million.xml" #fileName = "massive_100000.xml" fileName = join(self.testsPath, 'EMX/EMXread.emx') emxData = EmxData() emxData.read(fileName) m1 = EmxMicrograph('mic', 1) m1.set('acceleratingVoltage', 100.) m1.set('defocusU', 1000.) m1.set('pixelSpacing__X', 5.6) m1.set('pixelSpacing__Y', 5.7) m2 = EmxMicrograph('mic', 2) m2.set('acceleratingVoltage', 200.) m2.set('defocusUAngle', 135.) p1 = EmxParticle('parti', 1) p1.set('boxSize__X', 11) p1.set('boxSize__Y', 33) p1.set('defocusU', 1000.) p1.set('pixelSpacing__X', 55.6) p1.set('pixelSpacing__Y', 55.7) p1.set('transformationMatrix__t11', 11.1) p1.set('transformationMatrix__t12', 12.1) p1.set('transformationMatrix__t13', 13.1) p1.set('transformationMatrix__t14', 14.1) p1.set('transformationMatrix__t21', 21.1) p1.set('transformationMatrix__t24', 24.1) p1.set('transformationMatrix__t31', 31.1) p1.set('transformationMatrix__t32', 32.1) p1.set('transformationMatrix__t33', 33.1) p1.set('transformationMatrix__t34', 34.1) p1.setMicrograph(m1) self.assertTrue(emxData.objLists[MICROGRAPH][0].strongEq(m1)) self.assertTrue(emxData.objLists[MICROGRAPH][1].strongEq(m2)) self.assertTrue(emxData.objLists[PARTICLE][0].strongEq(p1)) def test_31_firstObject(self): #fileName = "massive_million.xml" #fileName = "massive_100000.xml" fileName = join(self.testsPath, 'EMX/EMXread.emx') emxData = EmxData() mic = emxData.readFirstObject(MICROGRAPH, fileName) m1 = EmxMicrograph('mic', 1) self.assertEqual(mic, m1, "first micrograph differ from expected") particle = emxData.readFirstObject(PARTICLE, fileName) p1 = EmxParticle('parti', 1) self.assertEqual(particle, p1, "first particle differ from expected") def test_35size(self): emxData = EmxData() p1 = EmxParticle('part', 1) p1.set('defocusU', 1000.10) p1.set('pixelSpacing__X', 5.66) p1.set('pixelSpacing__Y', 5.77) emxData.addObject(p1) m1 = EmxMicrograph('mic', 1) m1.set('acceleratingVoltage', 100) m1.set('defocusU', 1000.) m1.set('pixelSpacing__X', 5.6) m1.set('pixelSpacing__Y', 5.7) for i in range(1, 10): m1.set('index', i) emxData.addObject(m1) self.assertEqual(emxData.size(), 10) def test_40write(self): fileName = join(self.testsPath, 'EMX/EMXwrite.emx') emxData = EmxData() for i in range(1, 3): m1 = EmxMicrograph('mic', i) m1.set('acceleratingVoltage', 100) m1.set('defocusU', 1000.) m1.set('pixelSpacing__X', 5.6) m1.set('pixelSpacing__Y', 5.7) emxData.addObject(m1) p1 = EmxParticle('part', 1) p1.set('defocusU', 1000.10) p1.set('pixelSpacing__X', 5.66) p1.set('pixelSpacing__Y', 5.77) p1.set('transformationMatrix__t11', 11) p1.set('transformationMatrix__t12', 12) p1.set('transformationMatrix__t13', 13) p1.set('transformationMatrix__t14', 14) p1.set('transformationMatrix__t21', 21) p1.set('transformationMatrix__t22', 22) p1.set('transformationMatrix__t23', 23) p1.set('transformationMatrix__t24', 24) p1.set('transformationMatrix__t31', 31) p1.set('transformationMatrix__t32', 32) p1.set('transformationMatrix__t33', 33) p1.set('transformationMatrix__t34', 34) p1.setMicrograph(m1) #TODO: check the following line #p1.addForeignKey(MICROGRAPH,m1) emxData.addObject(p1) fileName2 = os.path.join('/tmp', 'EMXwrite.emx') emxData.write(fileName2) #print "kdiff3", fileName,fileName2 self.assertTrue(filecmp.cmp(fileName, fileName2)) if os.path.exists(fileName2): os.remove(fileName2) def test_50MasiveReadWrite(self): """This is not really a test but an auxiliary function """ fileName2 = join(self.testsPath, 'EMX/EMXMasiveWrite.emx') emxDataW = EmxData() emxDataR = EmxData() numberMic = 3 numberPartPerMic = 2 # numberMic=100 # numberPartPerMic = 1000 for i in range(1, numberMic): m1 = EmxMicrograph('mic', i) m1.set('acceleratingVoltage', 100) m1.set('defocusU', 1000.) m1.set('pixelSpacing__X', 5.6) m1.set('pixelSpacing__Y', 5.7) emxDataW.addObject(m1) for p in range(1, numberPartPerMic): p1 = EmxParticle('part', p) p1.set('defocusU', 1000.10) p1.set('pixelSpacing__X', 5.66) p1.set('pixelSpacing__Y', 5.77) p1.setMicrograph(m1) emxDataW.addObject(p1) fn = os.path.join('/tmp', 'EMXMasiveWrite.emx') fn2 = fn.replace('.emx', '2.emx') emxDataW.write(fn) emxDataR.read(fn) emxDataR.write(fn2) self.assertTrue(filecmp.cmp(fn, fn2)) #print "kdiff3", fn,fn+"2" if os.path.exists(fn): os.remove(fn) if os.path.exists(fn2): os.remove(fn2) def test_60iterate(self): #fileName = "massive_million.xml" #fileName = "massive_100000.xml" fileName = join(self.testsPath, 'EMX/EMXread.emx') emxData = EmxData() emxData.read(fileName) _list = [] m1 = EmxMicrograph('mic', 1) m1.set('acceleratingVoltage', 100.) m1.set('defocusU', 1000.) m1.set('pixelSpacing__X', 5.6) m1.set('pixelSpacing__Y', 5.7) _list.append(m1) m2 = EmxMicrograph('mic', 2) m2.set('acceleratingVoltage', 200.) m2.set('defocusUAngle', 135.) _list.append(m2) p1 = EmxParticle('parti', 1) p1.set('boxSize__X', 11) p1.set('boxSize__Y', 33) p1.set('defocusU', 1000.) p1.set('pixelSpacing__X', 55.6) p1.set('pixelSpacing__Y', 55.7) p1.set('transformationMatrix__t11', 11.1) p1.set('transformationMatrix__t12', 12.1) p1.set('transformationMatrix__t13', 13.1) p1.set('transformationMatrix__t14', 14.1) p1.set('transformationMatrix__t21', 21.1) p1.set('transformationMatrix__t24', 24.1) p1.set('transformationMatrix__t31', 31.1) p1.set('transformationMatrix__t32', 32.1) p1.set('transformationMatrix__t33', 33.1) p1.set('transformationMatrix__t34', 34.1) def test_70schema(self): xmlFile = join(self.testsPath, 'EMX/EMXwrite.emx') (code, _out, _err) = validateSchema(xmlFile) self.assertEqual(code, 0) xmlFile = join(self.testsPath, 'EMX/EMXwrite_badly_formed.emx') try: validateSchema(xmlFile) except ValidateError, v: print "EXCEPTION TESTING STARTS HERE: an Error message should appear. It is OK disregard it." print "Validate Error" print v.getCode(), v.getMessage() print "EXCEPTION TESTING ENDS HERE." except Exception, e: print "ERROR; we should have never arrive here:", e self.assertEqual(1, 0)
def runJavaJar(memory, jarName, args, batchMode=True): from protlib_filesystem import getXmippPath jarPath = getXmippPath(jarName) runJavaIJapp(memory, '-jar %s' % jarPath, args, batchMode)
def getProgramsDbName(): return os.path.join(getXmippPath(), '.xmipp_programs.sqlite')
def getXmippPrograms(): '''Return the list of Xmipp's programs, taken from from bin/ folder''' from glob import glob programs = [os.path.basename(p) for p in glob(os.path.join(getXmippPath(), 'bin', 'xmipp_*'))] programs.sort() return programs
def run(self): volfile = self.getParam("-i") if not xmippExists(volfile): print "ERROR: File " + volfile + "does not exist\n" sys.exit(1) mode = self.getParam("-m") angulardistfile = self.getParam("-a") if angulardistfile == "none": angulardistfile = None else: if not exists(angulardistfile): # either file does not exists or has a blockname if not (existsBlockInMetaDataFile(angulardistfile)): # check blockname print "ERROR: File " + angulardistfile + "does not exist or block is missing\n" sys.exit(1) spheres_color = self.getParam("-a", 1) spheres_distance = self.getParam("-a", 2) spheres_maxradius = self.getParam("-a", 3) isprojector = mode == "projector" if isprojector: size = self.getParam("-m", 1) padding_factor = self.getDoubleParam("-m", 2) max_freq = self.getDoubleParam("-m", 3) spline_degree_str = self.getParam("-m", 4) if spline_degree_str.lower() == "NEAREST".lower(): spline_degree = NEAREST elif spline_degree_str.lower() == "LINEAR".lower(): spline_degree = LINEAR elif spline_degree_str.lower() == "BSPLINE2".lower(): spline_degree = BSPLINE2 elif spline_degree_str.lower() == "BSPLINE3".lower(): spline_degree = BSPLINE3 elif spline_degree_str.lower() == "BSPLINE4".lower(): spline_degree = BSPLINE4 # print spline_degree voxelSize = self.getParam("-s") if voxelSize == "none": voxelSize = None port = self.getFreePort() if not port: print "ERROR: Port is not available\n" sys.exit(1) chimera = which("chimera") if chimera is None: print "ERROR: Chimera is not available\n" sys.exit(1) serverfile = getXmippPath("libraries/bindings/chimera/xmipp_chimera_server.py") # command = "export XMIPP_CHIMERA_PORT=%d; chimera %s &" % (port,serverfile) command = "chimera --script '%s %s' &" % (serverfile, port) system(command) if isprojector: XmippProjectionExplorer( volfile, port, [angulardistfile, spheres_color, spheres_distance, spheres_maxradius], size, padding_factor, max_freq, spline_degree, voxelSize, ) # print 'created projection explorer' elif mode == "viewer": client = XmippChimeraClient( volfile, port, [angulardistfile, spheres_color, spheres_distance, spheres_maxradius], voxelSize )