""" x2mtz.py: CCP4 GUI Project Copyright (C) 2015 STFC This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3, modified in accordance with the provisions of the license to address the requirements of UK law. You should have received a copy of the modified GNU Lesser General Public License along with this library. If not, copies may be downloaded from http://www.ccp4.ac.uk/ccp4license.php This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. """ ''' Base class for importing reflection data provides processOutputFiles() method to split mtz by either taking columns specified by HKLIN_OBS_COLUMNS and HKLIN_FREER_COLUMN or by finding best choice automatically ''' import os,shutil from core.CCP4PluginScript import CPluginScript from core import CCP4Utils from core.CCP4ErrorHandling import * class x2mtz(CPluginScript): TASKNAME = 'x2mtz' MAINTAINER = 'liz.potterton@york.ac.uk' TASKMODULE = 'test' ERROR_CODES = { 301 : { 'description' : 'Input data file not found' }, 302 : { 'description' : 'Failed automatic search for best reflection and freer daa in converted file' } } def processOutputFiles(self): outputData = self.container.outputData inputData = self.container.inputData hklout = outputData.HKLOUT self.freeRcolumnLabel = None #print 'x2mtz.process',hklout if not hklout.exists(): self.appendErrorReport(301) return CPluginScript.FAILED #print '\nx2mtz content', inputData.HKLIN.getFileContent() iBestObs = -1 iFree = -1 #print 'inputData.HKLIN_OBS_COLUMNS', inputData.HKLIN_OBS_COLUMNS if not inputData.HKLIN_OBS_COLUMNS.isSet() or not inputData.HKLIN_FREER_COLUMN.isSet(): #Try to figure the 'best' obs data and freer data in the input file columnGroups = hklout.fileContent.getColumnGroups() # for cg in columnGroups: # print 'processOutputFiles',cg.get() # print "* type",cg.columnGroupType for ii in range(len(columnGroups)): if columnGroups[ii].columnGroupType == 'FreeR': iFree = ii elif columnGroups[ii].columnGroupType == 'Obs': #print "@cg ", columnGroups[ii].contentFlag, columnGroups[iBestObs].contentFlag if iBestObs<0 or columnGroups[ii].contentFlag=0: #print 'Setting content flag',columnGroups[iBestObs].contentFlag,self.container.outputData.OBSOUT.columnNames(True) outputData.OBSOUT.contentFlag = columnGroups[iBestObs].contentFlag outputData.OBSOUT.annotation = outputData.OBSOUT.qualifiers('guiLabel')+' from '+inputData.HKLIN.stripedName() mtzOut.append('OBSOUT') progCol.append(str(columnGroups[iBestObs].columnList[0].columnLabel)) for col in columnGroups[iBestObs].columnList[1:]: progCol[-1] += ','+str(col.columnLabel) if inputData.HKLIN_FREER_COLUMN.isSet(allowDefault=False): mtzOut.append('FREEOUT') progCol.append(inputData.HKLIN_FREER_COLUMN.__str__()) outputData.FREEOUT.annotation = outputData.FREEOUT.qualifiers('guiLabel')+' from '+inputData.HKLIN.stripedName() elif iFree>=0: outputData.FREEOUT.annotation = outputData.FREEOUT.qualifiers('guiLabel')+' from '+inputData.HKLIN.stripedName() mtzOut.append('FREEOUT') self.freeRcolumnLabel = str(columnGroups[iFree].columnList[0].columnLabel) progCol.append(self.freeRcolumnLabel) #print 'x2mtz to splitHklout',mtzOut,progCol err = self.splitHklout(infile=str(hklout),programColumnNames=progCol,miniMtzsOut=mtzOut) #print 'x2mtz splitHklout err',err if err.maxSeverity()>SEVERITY_WARNING: print 'ERROR in splitHklout' print err.report() return CPluginScript.FAILED else: return CPluginScript.SUCCEEDED