Skip to content

Commit

Permalink
Merge pull request I2PC#332 from I2PC/v1.0
Browse files Browse the repository at this point in the history
RELEASE V1.0.0  2016-02-20
  • Loading branch information
delarosatrevin committed Feb 20, 2016
2 parents 23fa87d + 035ddfe commit c2abbbe
Show file tree
Hide file tree
Showing 20 changed files with 443 additions and 326 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

## v1.0.0 (2016-02-15) Augusto
## v1.0.0 (2016-02-20) Augusto

- Allows to combine several EM software packages (~ 100 protocols):
- All protocols from Xmipp
Expand Down
2 changes: 1 addition & 1 deletion config/workflows/workflow_betagal1.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"alignFrame0": 0,
"alignFrameN": 0,
"doGPU": false,
"GPUCore": 1,
"GPUCore": 0,
"winSize": 150,
"sumFrame0": 0,
"sumFrameN": 0,
Expand Down
13 changes: 12 additions & 1 deletion pyworkflow/em/packages/grigoriefflab/bibtex.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,18 @@
keywords = "Electron microscopy, Maximum likelihood, Classification, Single particle, Protein structure "
}
@Article{Rohou2015,
Author="Rohou, A. and Grigorieff, N. ",
Title="{{C}{T}{F}{F}{I}{N}{D}4: {F}ast and accurate defocus estimation from electron micrographs}",
Journal="J. Struct. Biol.",
Year="2015",
Volume="192",
Number="2",
Pages="216--221",
Month="Nov",
doi = "http://dx.doi.org/10.1016/j.jsb.2015.08.008",
url = "http://www.sciencedirect.com/science/article/pii/S1047847715300460"
}
"""


Expand Down
5 changes: 3 additions & 2 deletions pyworkflow/em/packages/grigoriefflab/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,13 @@ def readCtfModel(ctfModel, filename, ctf4=False):
result = parseCtffind4Output(filename)
if result is None:
setWrongDefocus(ctfModel)
ctfFit, ctfResolution = -999, -999
ctfFit, ctfResolution, ctfPhaseShift = -999, -999, -999
else:
defocusU, defocusV, defocusAngle, _, ctfFit, ctfResolution = result
defocusU, defocusV, defocusAngle, ctfPhaseShift, ctfFit, ctfResolution = result
ctfModel.setStandardDefocus(defocusU, defocusV, defocusAngle)
ctfModel._ctffind4_crossCorrelation = Float(ctfFit)
ctfModel._ctffind4_ctfResolution = Float(ctfResolution)
ctfModel._ctffind4_ctfPhaseShift = Float(ctfPhaseShift)


def geometryFromMatrix(matrix):
Expand Down
108 changes: 80 additions & 28 deletions pyworkflow/em/packages/grigoriefflab/protocol_ctffind.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,40 @@ class ProtCTFFind(em.ProtCTFMicrographs):


def _defineProcessParams(self, form):
form.addParam('useCftfind4', params.BooleanParam, default=True,
form.addParam('useCtffind4', params.BooleanParam, default=True,
label="Use ctffind4 to estimate the CTF?",
help='If is true, the protocol will use ctffind4 instead of ctffind3')
form.addParam('astigmatism', params.FloatParam, default=100.0,
label='Expected (tolerated) astigmatism', expertLevel=params.LEVEL_ADVANCED,
condition='useCftfind4', )
label='Expected (tolerated) astigmatism (A)',
expertLevel=params.LEVEL_ADVANCED,
help='Astigmatism values much larger than this will be penalised '
'(Angstroms; set negative to remove this restraint)',
condition='useCtffind4')
form.addParam('findPhaseShift', params.BooleanParam, default=False,
label="Find additional phase shift?", condition='useCftfind4',
expertLevel=params.LEVEL_ADVANCED,)

label="Find additional phase shift?", condition='useCtffind4',
help='If the data was collected with phase plate, this will find '
'additional phase shift due to phase plate',
expertLevel=params.LEVEL_ADVANCED)

group = form.addGroup('Phase shift parameters')
group.addParam('minPhaseShift', params.FloatParam, default=0.0,
label="Minimum phase shift (rad)", condition='findPhaseShift',
help='Lower bound of the search for additional phase shift. '
'Phase shift is of scattered electrons relative to '
'unscattered electrons. In radians.',
expertLevel=params.LEVEL_ADVANCED)
group.addParam('maxPhaseShift', params.FloatParam, default=3.15,
label="Maximum phase shift (rad)", condition='findPhaseShift',
help='Upper bound of the search for additional phase shift. '
'Phase shift is of scattered electrons relative to '
'unscattered electrons. In radians. '
'Please use value between 0.10 and 3.15',
expertLevel=params.LEVEL_ADVANCED)
group.addParam('stepPhaseShift', params.FloatParam, default=0.2,
label="Phase shift search step (rad)", condition='findPhaseShift',
help='Step size for phase shift search (radians)',
expertLevel=params.LEVEL_ADVANCED)

#--------------------------- STEPS functions ---------------------------------------------------
def _estimateCTF(self, micFn, micDir, micName):
""" Run ctffind, 3 or 4, with required parameters """
Expand All @@ -71,7 +95,9 @@ def _estimateCTF(self, micFn, micDir, micName):
if downFactor != 1:
#Replace extension by 'mrc' cause there are some formats that cannot be written (such as dm3)
import pyworkflow.em.packages.xmipp3 as xmipp3
self.runJob("xmipp_transform_downsample","-i %s -o %s --step %f --method fourier" % (micFn, micFnMrc, downFactor), env=xmipp3.getEnviron())
self.runJob("xmipp_transform_downsample",
"-i %s -o %s --step %f --method fourier" % (micFn, micFnMrc, downFactor),
env=xmipp3.getEnviron())
self._params['scannedPixelSize'] = self.inputMicrographs.get().getScannedPixelSize() * downFactor
else:
micFnMrc = self._getTmpPath(pwutils.replaceBaseExt(micFn, "mrc"))
Expand Down Expand Up @@ -122,12 +148,7 @@ def _createNewCtfModel(self, mic):
out = self._getCtfOutPath(micDir)
psdFile = self._getPsdPath(micDir)
ctfModel2 = em.CTFModel()

if not self.useCftfind4:
readCtfModel(ctfModel2, out)
else:
readCtfModel(ctfModel2, out, True)

readCtfModel(ctfModel2, out, ctf4=self.useCtffind4.get())
ctfModel2.setPsdFile(psdFile)
ctfModel2.setMicrograph(mic)
return ctfModel2
Expand All @@ -144,12 +165,7 @@ def _createOutputStep(self):
out = self._getCtfOutPath(micDir)

ctfModel = em.CTFModel()

if not self.useCftfind4:
readCtfModel(ctfModel, out)
else:
readCtfModel(ctfModel, out, True)

readCtfModel(ctfModel, out, ctf4=self.useCtffind4.get())
ctfModel.setPsdFile(psdFile)
ctfModel.setMicrograph(mic)

Expand All @@ -164,16 +180,23 @@ def _createOutputStep(self):
#--------------------------- INFO functions ----------------------------------------------------
def _validate(self):
errors = []
if self.useCftfind4:
ctffind = CTFFIND4_PATH
else:
ctffind = CTFFIND_PATH
ctffind = CTFFIND4_PATH if self.useCtffind4 else CTFFIND_PATH
if not os.path.exists(ctffind):
errors.append('Missing %s' % ctffind)

valueStep = round(self.stepPhaseShift.get(), 2)
valueMin = round(self.minPhaseShift.get(), 2)
valueMax = round(self.maxPhaseShift.get(), 2)

if not (self.minPhaseShift < self.maxPhaseShift and
valueStep <= (valueMax-valueMin) and
0.10 <= valueMax <= 3.15):
errors.append('Wrong values for phase shift search.')

return errors

def _citations(self):
return ['Mindell2003']
return ['Rohou2015'] if self.useCtffind4 else ['Mindell2003']

def _methods(self):
if self.inputMicrographs.get() is None:
Expand All @@ -194,12 +217,15 @@ def _prepareCommand(self):
self._params['lowRes'] = 50
self._params['highRes'] = sampling / self._params['highRes']
self._params['step_focus'] = 500.0
if not self.useCftfind4:
if not self.useCtffind4:
self._argsCtffind3()
else:
self._params['astigmatism'] = self.astigmatism.get()
if self.findPhaseShift:
self._params['phaseShift'] = "yes"
self._params['minPhaseShift'] = self.minPhaseShift.get()
self._params['maxPhaseShift'] = self.maxPhaseShift.get()
self._params['stepPhaseShift'] = self.stepPhaseShift.get()
else:
self._params['phaseShift'] = "no"
self._argsCtffind4()
Expand All @@ -226,12 +252,15 @@ def _prepareRecalCommand(self, ctfModel):
self._params['maxDefocus'] = max([float(line[0]), float(line[1])])
self._params['windowSize'] = size

if not self.useCftfind4:
if not self.useCtffind4:
self._argsCtffind3()
else:
self._params['astigmatism'] = self.astigmatism.get()
if self.findPhaseShift:
self._params['phaseShift'] = "yes"
self._params['minPhaseShift'] = self.minPhaseShift.get()
self._params['maxPhaseShift'] = self.maxPhaseShift.get()
self._params['stepPhaseShift'] = self.stepPhaseShift.get()
else:
self._params['phaseShift'] = "no"
self._argsCtffind4()
Expand All @@ -248,7 +277,29 @@ def _argsCtffind3(self):

def _argsCtffind4(self):
self._program = 'export OMP_NUM_THREADS=1; ' + CTFFIND4_PATH
self._args = """ << eof
if self.findPhaseShift:
self._args = """ << eof
%(micFn)s
%(ctffindPSD)s
%(sampling)f
%(voltage)f
%(sphericalAberration)f
%(ampContrast)f
%(windowSize)d
%(lowRes)f
%(highRes)f
%(minDefocus)f
%(maxDefocus)f
%(step_focus)f
%(astigmatism)f
%(phaseShift)s
%(minPhaseShift)f
%(maxPhaseShift)f
%(stepPhaseShift)f
eof
"""
else:
self._args = """ << eof
%(micFn)s
%(ctffindPSD)s
%(sampling)f
Expand Down Expand Up @@ -276,7 +327,7 @@ def _parseOutput(self, filename):
""" Try to find the output estimation parameters
from filename. It search for a line containing: Final Values.
"""
if not self.useCftfind4:
if not self.useCtffind4:
return parseCtffindOutput(filename)
else:
return parseCtffind4Output(filename)
Expand All @@ -287,3 +338,4 @@ def _getCTFModel(self, defocusU, defocusV, defocusAngle, psdFile):
ctf.setPsdFile(psdFile)

return ctf

Loading

0 comments on commit c2abbbe

Please sign in to comment.