Ctffind4 Relion 1.4 segmentation fault with --old-school-input

I had trouble running ctffind4.0.17 when it is called from the Relion 1.4 gui. When I run it with this in the Ctffind Executable box "/Applications/ctffind-4.0.17/bin/ctffind --old-school-input" in the , I got this output:

jjwwong$ Executing: mpirun -n 2 `which relion_run_ctffind_mpi` --i "all_micrographs.star" --o "all_micrographs_ctf.star" --ctfWin -1 --CS 2 --HT 300 --AmpCnst 0.1 --XMAG 39548 --DStep 14 --Box 512 --ResMin 100 --ResMax 7 --dFMin 5000 --dFMax 50000 --FStep 500 --dAst 0 --ctffind_exe "/Applications/ctffind-4.0.17/bin/ctffind --old-school-input" &
=== RELION MPI setup ===
+ Number of MPI processes = 2
+ Master (0) runs on host = dn0a22f235.sunet
=================
+ Slave 1 runs on host = dn0a22f235.sunet
Using CTFFINDs executable in: /Applications/ctffind-4.0.17/bin/ctffind --old-school-input
to estimate CTF parameters for the following micrographs:
* Micrographs/Falcon_2012_06_12-14_33_35_0.mrc
* Micrographs/Falcon_2012_06_12-14_57_34_0.mrc

(several more .mrc files)

Estimating CTF parameters using Niko Grigorieff's CTFFIND ...
000/??? sec ~~(,_,"> [oo]
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0 0x10a83c879
#1 0x10a83bc45
#2 0x7fff870135a9

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0 0x106848879
#1 0x106847c45
#2 0x7fff870135a9
Segmentation fault

(Segmentation fault repeats many more times)

Backtrace for this error:
#0 0x1074ec879
#1 0x1074ebc45
#2 0x7fff870135a9
Segmentation fault
2/ 2 sec ............................................................~~(,_,">
+++ RELION: command line arguments (with defaults for optional ones between parantheses) +++
====== General options =====
====== CTF estimation =====
--i : STAR file with all input micrographs, or a unix wildcard to all micrograph files, e.g. "mics/*.mrc"
--o (micrographs_ctf.star) : Name for the STAR file with CTF params for each micrograph
--only_make_star (false) : Don't run CTFFIND, only join the logfile results in a STAR file
--only_do_unfinished (false) : Only run CTFFIND for those micrographs for which there is not yet a logfile with Final values.
--ctfWin (-1) : Size (in pixels) of a centered, squared window to use for CTF-estimation
--ctffind_exe () : Location of ctffind executable (or through RELION_CTFFIND_EXECUTABLE environment variable)
--CS (2.0) : Spherical Aberration (mm)
--HT (300) : Voltage (kV)
--AmpCnst (0.1) : Amplitude constrast
--XMAG (60000) : Magnification
--DStep (14) : Detector pixel size (um)
--Box (512) : Size of the boxes to calculate FFTs
--ResMin (100) : Minimum resolution (in A) to include in calculations
--ResMax (7) : Maximum resolution (in A) to include in calculations
--dFMin (10000) : Minimum defocus value (in A) to search
--dFMax (50000) : Maximum defocus value (in A) to search
--FStep (250) : defocus step size (in A) for search
--dAst (0) : amount of astigmatism (in A)
ERROR: cannot find line with Cs[mm], HT[kV], etc values in Micrographs/Falcon_2012_06_12-14_33_35_0_ctffind3.log
File: src/ctffind_runner.cpp line: 297
--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD
with errorcode 1.

NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.
--------------------------------------------------------------------------

I believe the relevant parts in my environment were
LD_LIBRARY_PATH=/Applications/relion-1.4/lib:/Applications/openmpi-1.10.2/lib:
PATH=/Applications/ctffind-4.0.17/bin:/Applications/relion-1.4/bin:/Applications/openmpi-1.10.2/bin:/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
RELION_RESMAP_EXECUTABLE=“/Applications/ResMap-1.1.4-mac64”
LANG=en_US.UTF-8
RELION_CTFFIND_EXECUTABLE=“/Applications/ctffind-4.0.17/bin/ctffind”
My system is Mac OS X 10.9.5, both ctffind and relion compiled with gfortran 6.1.0 from the GCC package.

I then tried to run ctffind on its own to see if it by itself was working. Entering ctffind into the command line gives

** Welcome to CTFFind **
Version - 4.0.17

Input Mode: Interactive
Date & Time: 2016-05-13 01:00:02

Copyright 2015 Howard Hughes Medical Institute. All rights reserved.
Use is subject to Janelia Farm Research Campus Software Copyright 1.1
license terms ( http://license.janelia.org/license/jfrc_copyright_1_1.html )

Input image file name [input.mrc] :

When I input the name of the file in the directory I opened ctffind in, I get

[Falcon_2012_06_12-17_26_54_0.mrc] :
Output diagnostic filename [diagnostic_output.mrc] :
Pixel size [14] :
Acceleration voltage [300] :
Spherical aberration [2] :
Amplitude contrast [.1] :
Size of power spectrum to compute [512] :
Minimum resolution [30.0] :
Maximum resolution [5.0] :
Minimum defocus [5000.0] :
Maximum defocus [50000.0] :
Defocus search step [500.0] :
Expected (tolerated) astigmatism [100.0] :
Find additional phase shift? [no] :

Summary information for file Falcon_2012_06_12-17_26_54_0.mrc
Number of columns, rows, sections: 1950 1950 1
MRC data mode: 2
Bit depth: 32
Pixel size: 3.540 3.540 .000
Label 1:
Label 2:
Label 3:
Label 4:
Label 5:
Label 6:
Label 7:
Label 8:
Label 9:
Label 10:

Working on micrograph 1 of 1

0% [ ] ???h:??m:??s
100% [==============================] done!

Estimated defocus values : 39234.70 , 39161.10 Angstroms
Estimated azimuth of astigmatism: -84.04 degrees
Score : -.72536
Thon rings with good fit up to : 19.7 Angstroms

Summary of results : diagnostic_output.txt
Diagnostic images : diagnostic_output.mrc
Detailled results, including 1D fit profiles: diagnostic_output_avrot.txt
Use this command to plot 1D fit profiles : ctffind_plot_results.sh diagnostic_output_avrot.txt

Total execution time : 23 seconds
2016-05-13 14:06:34 : CTFFind finished cleanly.

However, when I start ctffind with % ctffind --old-school-input, which Relion requires according to the tutorial at http://www2.mrc-lmb.cam.ac.uk/groups/scheres/relion13_tutorial.pdf, I get this:

** Welcome to CTFFind **
Version - 4.0.17

Input Mode: Interactive
Date & Time: 2016-05-13 14:08:24

Copyright 2015 Howard Hughes Medical Institute. All rights reserved.
Use is subject to Janelia Farm Research Campus Software Copyright 1.1
license terms ( http://license.janelia.org/license/jfrc_copyright_1_1.html )

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0 0x109b92879
#1 0x109b91c45
#2 0x7fff870135a9
Segmentation fault: 11
joyces-imac-2:Micrographs jjwwong$

Is the --old-school-input option the issue? How can I solve this to get ctffind to be run properly from Relion?

Hi there,

Unfortunately, there is a bug in ctffind4 which only becomes apparent when using a ctffind4 binary compiled using the GNU compiler (gfortran). This bug has the effect that --old-school-input is not working.

Please see this thread for a workaround, which involves editing the source and recompiling:

http://grigoriefflab.janelia.org/node/5141

As pointed out in that thread, an alternative workaround is to compile using the Intel compiler if you have access to that.

Sorry about the trouble.

Alexis

In reply to by Alexis

I have tried to change the ctffind.f90 source code according to the forum thread you linked (changing old-school-input to =.true., commenting out the call my_user_input%UpdateDefaults() line. Now I get a new error:

Estimating CTF parameters using Niko Grigorieff's CTFFIND ...
000/??? sec ~~(,_,"> [oo]ctffind(1976,0x7fff7a904310) malloc: *** mach_vm_map(size=18446744071761305600) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

(repeats many times)

Operating system error: Cannot allocate memory
Memory allocation failed in xmallocarray

Error termination. Backtrace:
Memory allocation failed in xmallocarray

Error termination. Backtrace:
#0 0x10576c879
#1 0x10576d545
#2 0x10576d745
#3 0x10576bfe3
#0 0x101cb8879
#1 0x101cb9545
#4 0x105847a1c
#5 0x105339b92
#6 0x10533a203
#2 0x101cb9745
#3 0x101cb7fe3
#7 0x105385bbb
#8 0x10544f70e
#4 0x101d93a1c
#5 0x101880b92
#6 0x101881203
#7 0x1018ccbbb
#8 0x10199670e

(all of the above repeats many times)

Is there any way around this?

In reply to by JoyceW

I have not encountered this kind of error in the past. It looks like an OSX-specific memory allocation error. I'm afraid I have never used OSX and I don't have any useful insights on how to solve or circumvent this, other than perhaps try to run the job on downsampled micrographs to check whether the program runs correctly with more modest memory requirements.

I would recommend consulting OSX-specific resources and searching for this specific error message.

Alexis

In reply to by Alexis

In case it helps or is of interest, I recorded using Xcode's Instruments tool a run of relion calling ctffind where it crashes with the memory allocation error, and have attached the screenshots to the first post. It seems that the libfltk.1.3.dylib and CoreGraphics are the most memory intense processes, and there are a lot of them, but I don't know what to do about it from here. Is there a way to compile relion, ctffind, or whatever dependency package is causing the problem in such a way as to limit the memory allocation it asks for to something reasonable?

I was trying relion+ctffind using the images that came with the betagal Relion tutorial, which the manual says are already down sampled. The error and memory allocation size does not change if I tell it to run on a smaller selection of images (just 2).

In reply to by JoyceW

Btw, if I try to run the newly compiled ctffind that has the changed source code on its own by
dn0a22f8a0:Micrographs jjwwong$ ctffind Falcon_2012_06_12-14_33_35_0.mrc
I get this output

[3]+ ctffind Falcon_2012_06_12-14_33_35_0.mrc &
At line 217 of file src/ctffind.f90 (unit = 5, file = 'stdin')
Fortran runtime error: End of file

Error termination. Backtrace:
dn0a22f8a0:Micrographs jjwwong$ #0 0x10b1c0879
#1 0x10b1c1545
#2 0x10b1c1ca9
#3 0x10b28a0bb
#4 0x10b28a657
#5 0x10b2876f3
#6 0x10b28c6e4
#7 0x10add6d11
#8 0x10aea070e