Repository: spack/spack

Issue:
relion 3.1.0 released
https://github.com/spack/spack/blob/4af630308619afb40b1de89d1f7bac0f57b70a38/var/spack/repos/builtin/packages/relion/package.py#L20

https://github.com/3dem/relion/releases

> Everyone using RELION 3.0.x or 3.1 beta should upgrade to this version.


Discussion:
Would be better to add a url to this package so we can specify version tags to be extrapolated. See the libfabric package for reference on how this can be structured. 
I started updating the package, but it might take a bit more than expected to get it right since build appears to be broken even for v3.0.8 on:

* **Spack:** 0.15.4-710-125191931
* **Python:** 3.6.9
* **Platform:** linux-ubuntu18.04-broadwell

I just hacked the current package.py to install Relion 3.1: 

```py
from spack import *

class Relion(CMakePackage, CudaPackage):
    """RELION (for REgularised LIkelihood OptimisatioN, pronounce rely-on) is a
    stand-alone computer program that employs an empirical Bayesian approach to
    refinement of (multiple) 3D reconstructions or 2D class averages in
    electron cryo-microscopy (cryo-EM)."""

    homepage = "http://http://www2.mrc-lmb.cam.ac.uk/relion"
    git = "https://github.com/3dem/relion.git"

    version('3.1.0', url='https://github.com/3dem/relion/archive/3.1.0.zip', 
            sha256='8a7e751fa6ebcdf9f36046499b3d88e170c4da86d5ff9ad1914b5f3d178867a8')

    variant('gui', default=True, description="build the gui")
    variant('cuda', default=True, description="enable compute on gpu")
    variant('double', default=True, description="double precision (cpu) code")
    variant('double-gpu', default=False, description="double precision gpu")
    # if built with purpose=cluster then relion will link to gpfs libraries
    # if that's not desirable then use purpose=desktop
    variant('purpose', default='cluster', values=('cluster', 'desktop'),
            description="build relion for use in cluster or desktop")
    variant('build_type', default='RelWithDebInfo',
            description='The build type to build',
            values=('Debug', 'Release', 'RelWithDebInfo',
                    'Profiling', 'Benchmarking'))

    depends_on('mpi')
    depends_on('cmake@3:', type='build')
    depends_on('fftw precision=float,double')
    depends_on('fltk', when='+gui')
    depends_on('libtiff')

    depends_on('cuda', when='+cuda')
    depends_on('cuda@9:10.99', when='@3: +cuda')

    def cmake_args(self):

        carch = self.spec.variants['cuda_arch'].value[0]

        args = [
            '-DCMAKE_C_FLAGS=-g',
            '-DCMAKE_CXX_FLAGS=-g',
            '-DGUI=%s' % ('+gui' in self.spec),
            '-DDoublePrec_CPU=%s' % ('+double' in self.spec),
            '-DDoublePrec_GPU=%s' % ('+double-gpu' in self.spec),
        ]

        if '+cuda' in self.spec:
            # relion+cuda requires selecting cuda_arch
            if not carch:
                raise ValueError("select cuda_arch when building with +cuda")
            else:
                args += ['-DCUDA=ON', '-DCudaTexture=ON',
                         '-DCUDA_ARCH=%s' % (35)] # sm_35 worked for me but it should be determined by "crach"

        # these new values were added in relion 3
        # do not seem to cause problems with < 3
        else:
            args += ['-DMKLFFT=ON', '-DFORCE_OWN_TBB=ON', '-DALTCPU=ON']

        return args
```
@ashki23 Do you want to submit a PR to fix `relion` build and add v3.1? Feel free to ping me for review on that.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/relion/package.py b/var/spack/repos/builtin/packages/relion/package.py
--- a/var/spack/repos/builtin/packages/relion/package.py
+++ b/var/spack/repos/builtin/packages/relion/package.py
@@ -14,15 +14,14 @@ class Relion(CMakePackage, CudaPackage):
 
     homepage = "http://http://www2.mrc-lmb.cam.ac.uk/relion"
     git      = "https://github.com/3dem/relion.git"
+    url      = "https://github.com/3dem/relion/archive/3.1.0.zip"
 
-    # 3.1 is beta but referenced in published papers
-    # prefer stable 3.0 until no longer beta
-    version('3.1_beta', branch='ver3.1')
+    version('3.1.1', sha256='63e9b77e1ba9ec239375020ad6ff631424d1a5803cba5c608c09fd44d20b1618')
+    version('3.1.0', sha256='8a7e751fa6ebcdf9f36046499b3d88e170c4da86d5ff9ad1914b5f3d178867a8')
 
     # 3.0.8 latest release in 3.0 branch
-    # prefer for now
-    version('3.0.8', tag='3.0.8', preferred=True)
-    version('3.0.7', tag='3.0.7')
+    version('3.0.8', sha256='18cdd58e3a612d32413eb37e473fe8fbf06262d2ed72e42da20356f459260973')
+    version('3.0.7', sha256='a6d37248fc4d0bfc18f4badb7986dc1b6d6849baa2128b0b4dade13cb6991a99')
 
     # relion master contains development code
     # contains 3.0 branch code
@@ -40,15 +39,19 @@ class Relion(CMakePackage, CudaPackage):
             description='The build type to build',
             values=('Debug', 'Release', 'RelWithDebInfo',
                     'Profiling', 'Benchmarking'))
+    variant('mklfft', default=True, description='Use MKL rather than FFTW for FFT')
+    variant('allow_ctf_in_sagd', default=True, description='Allow CTF-modulation in SAGD, as specified in Claim 1 of patent US10,282,513B2')
 
     depends_on('mpi')
     depends_on('cmake@3:', type='build')
-    depends_on('fftw precision=float,double')
+    depends_on('fftw precision=float,double', when='~mklfft')
     depends_on('fltk', when='+gui')
     depends_on('libtiff')
 
     depends_on('cuda', when='+cuda')
     depends_on('cuda@9:', when='@3: +cuda')
+    depends_on('tbb', when='~cuda')
+    depends_on('mkl', when='~cuda +mklfft')
 
     def cmake_args(self):
 
@@ -60,6 +63,7 @@ def cmake_args(self):
             '-DGUI=%s' % ('+gui' in self.spec),
             '-DDoublePrec_CPU=%s' % ('+double' in self.spec),
             '-DDoublePrec_GPU=%s' % ('+double-gpu' in self.spec),
+            '-DALLOW_CTF_IN_SAGD=%s' % ('+allow_ctf_in_sagd' in self.spec),
         ]
 
         if '+cuda' in self.spec:
@@ -73,7 +77,7 @@ def cmake_args(self):
         # these new values were added in relion 3
         # do not seem to cause problems with < 3
         else:
-            args += ['-DMKLFFT=ON', '-DFORCE_OWN_TBB=ON', '-DALTCPU=ON']
+            args += ['-DMKLFFT=%s' % ('+mklfft' in self.spec), '-DALTCPU=ON']
 
         return args
 


Test patch: