Repository: spack/spack

Issue:
Installation issue: Ambert Tools 20

Hi,

We are trying to install AmberTools without success. We have downloaded the AmberTools20.tar.bz2 to the folder where spack is called (~). It gives us the following error.

```
==> Installing amber
==> No binary for amber found: installing from source
==> Error: FetchError: All fetchers failed

/shared/spack/lib/spack/spack/package.py:1270, in do_fetch:
       1267                                 self.spec.format('{name}{@version}'), ck_msg)
       1268
       1269        self.stage.create()
  >>   1270        err_msg = None if not self.manual_download else self.download_instr
       1271        self.stage.fetch(mirror_only, err_msg=err_msg)
       1272        self._fetch_time = time.time() - start_time
       1273
```
The spec is:
```
$ spack install amber@18.20 +mpi +openmp %intel
```

Information of the system
```
* **Spack:** 0.15.4-1609-caab89b
* **Python:** 3.8.6
* **Platform:** linux-centos7-zen2
```

The three stage folders present are empty
```
build_cache  
resource-AmberTools-atcyu4m75qh7radyd3t65acy5pofbzgi
spack-stage-amber-18.20-atcyu4m75qh7radyd3t65acy5pofbzgi
```

Maintainer @hseara 

There's a similar issue here but it's closed without any solution #14063 

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [x] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [x] I have run `spack maintainers <name-of-the-package>` and @mentioned any maintainers
- [x] I have uploaded the build log and environment files
- [x] I have searched the issues of this repo and believe this is not a duplicate



Discussion:
@hseara did you get a chance to look at this? It looks like the tarball was renamed from `Amber#` to `AmberTools#`. We also need to add version 20 for this to work.
I will have a look during this week.
Hi all, 
Please take into account the following:

- I am not related in any way to Amber of their development team.
- **Amber** is proprietary software with a very cheap and flexible license (whole departments with a single license). There are no direct download links for it. It basically provides the advanced MD engine `pmemd`.
-  **Ambertools** is free of charge, and its components are mostly released under the GNU General Public License (GPL). Amber requires people to fill a form in their [webpage](https://ambermd.org/GetAmber.php#ambertools) to download Ambertools.  However, there is also a working link ('http://ambermd.org/downloads/AmberTools{0}.tar.bz2') that I will add in the new spack commit I am working on. I hope they do not mind.

Ambertools can be used as a stand-alone package. Currently, this option is not offered by spack. Amber, however, requires the source code of Ambertools to be embedded in the installation source code of Amber for its installation. They share a large fraction of code.

Another point that I would like to clarify is that each Amber version only supports a very limited set of Ambertools to be compiled with. 
- Amber20: Ambertools20 and Ambertools21
- Amber18:Ambertools18 and Ambertools19
- Amber16: Ambertools16 and Ambertools17

Therefore, the package combination added to the package Amber18 and Ambertools20 is not possible. 

Finally, there are the following issues that need to be check:
- Starting from Amber20 cmake installer is also available and as far as I know, preferred. Therefore, it will be hard to keep compatibility with old releases. We might have to split the package between Amber and Amber-legacy if we want to continue supporting Amber 18 and 16. I will not make any effort to support even older versions.
-  There are some issues with new versions of gcc (>9) and Amber version 16 and 18.
-  Currently, when installing ambers without mpi (`spack install amber@18.19%gcc@9.3.0`), still pulls `openmpi` as a dependency due to netcdf. The only way to achieve the desired result is by issuing `spack install amber@18.19%gcc@9.3.0~mpi^netcdf-c~mpi^hdf5~mpi'

For the rest, even without any changes, the package works as expected. The spack installation command must be issued from a directory containing the files Amber18.tar.bz2 and AmberTools19.tar.bz2 with the correct hashes.

I will try to implement some of the changes mentioned above, although I would appreciate some comments on how to proceed due to the differences between Amber20 and previous versions of installation methods. 
@hseara this all sounds good to me. I think it's safe to use that download link in the package, although I'm not a legal person. We do something similar for the `jdk` package. In that way, it should be easy to use the newest version of AmberTools that supports the chosen version of Amber.

For the changing build system question, that's much more open-ended. See https://github.com/spack/spack/pull/12941#issuecomment-538105434 for a list of packages in Spack that have changed build systems. You can look to those for examples of how to handle things. We don't yet have an agreed upon approach to handle changing build systems. Generally, I suggest that packages extend the `Package` base class and use `@when('@20:')` decorators for the new `install` method. `arpack-ng` is a good example of this. In the long run, I agree that removing those old versions is probably best. #20767 and #15896 have a proposed policy for handling this, but it hasn't been merged yet.

Let me know if you have any other questions!

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/amber/package.py b/var/spack/repos/builtin/packages/amber/package.py
--- a/var/spack/repos/builtin/packages/amber/package.py
+++ b/var/spack/repos/builtin/packages/amber/package.py
@@ -12,13 +12,14 @@ class Amber(Package, CudaPackage):
     """Amber is a suite of biomolecular simulation programs together
        with Amber tools.
 
-       Note: The version number is composed of the Amber version (major)
-       and the tools version (minor). A manual download is required for
-       both Amber and Amber tools.
-       Spack will search your current directory for the download files.
-       Alternatively, add the files to a mirror so that Spack can find them.
-       For instructions on how to set up a mirror, see
-       http://spack.readthedocs.io/en/latest/mirrors.html"""
+       A manual download is required for Ambers. Spack will search your current
+       directory for the download files. Alternatively, add the files to a mirror
+       so that Spack can find them. For instructions on how to set up a mirror, see
+       http://spack.readthedocs.io/en/latest/mirrors.html
+
+       Note: Only certain versions of ambertools are compatible with amber.
+       Only the latter version of ambertools for each amber version is supported.
+       """
 
     homepage = "http://ambermd.org/"
     url = "file://{0}/Amber18.tar.bz2".format(os.getcwd())
@@ -26,35 +27,40 @@ class Amber(Package, CudaPackage):
 
     maintainers = ['hseara']
 
-    def url_for_version(self, version):
-        url = "file://{0}/Amber{1}.tar.bz2".format(
-            os.getcwd(), version.up_to(1))
-        return url
-
     version(
-        '18.20', sha256='2060897c0b11576082d523fb63a51ba701bc7519ff7be3d299d5ec56e8e6e277')
+        '20', sha256='a4c53639441c8cc85adee397933d07856cc4a723c82c6bea585cd76c197ead75')
     version(
-        '18.19', sha256='2060897c0b11576082d523fb63a51ba701bc7519ff7be3d299d5ec56e8e6e277')
+        '18', sha256='2060897c0b11576082d523fb63a51ba701bc7519ff7be3d299d5ec56e8e6e277')
     version(
-        '16.16', sha256='3b7ef281fd3c46282a51b6a6deed9ed174a1f6d468002649d84bfc8a2577ae5d')
+        '16', sha256='3b7ef281fd3c46282a51b6a6deed9ed174a1f6d468002649d84bfc8a2577ae5d',
+        deprecated=True)
 
-    resources = [
+    resources = {
         # [version amber, version ambertools , sha256sum]
-        ('18', '20', 'b1e1f8f277c54e88abc9f590e788bbb2f7a49bcff5e8d8a6eacfaf332a4890f9'),
-        ('18', '19', '0c86937904854b64e4831e047851f504ec45b42e593db4ded92c1bee5973e699'),
-        ('16', '16', '7b876afe566e9dd7eb6a5aa952a955649044360f15c1f5d4d91ba7f41f3105fa'),
-    ]
-    for ver, ambertools_ver, checksum in resources:
-        resource(when='@{0}.{1}'.format(ver, ambertools_ver),
+        '20': ('20', 'b1e1f8f277c54e88abc9f590e788bbb2f7a49bcff5e8d8a6eacfaf332a4890f9'),
+        '18': ('19', '0c86937904854b64e4831e047851f504ec45b42e593db4ded92c1bee5973e699'),
+        '16': ('16', '7b876afe566e9dd7eb6a5aa952a955649044360f15c1f5d4d91ba7f41f3105fa'),
+    }
+    for ver, (ambertools_ver, ambertools_checksum) in resources.items():
+        resource(when='@{0}'.format(ver),
                  name='AmberTools',
-                 url='file://{0}/AmberTools{1}.tar.bz2'.format(os.getcwd(),
-                                                               ambertools_ver),
-                 sha256=checksum,
+                 url='http://ambermd.org/downloads/AmberTools{0}.tar.bz2'.format(
+                      ambertools_ver),
+                 sha256=ambertools_checksum,
                  destination='',
                  placement='ambertools_tmpdir',
                  )
 
     patches = [
+        ('20', '1', '10780cb91a022b49ffdd7b1e2bf4a572fa4edb7745f0fc4e5d93b158d6168e42'),
+        ('20', '2', '9c973e3f8f33a271d60787e8862901e8f69e94e7d80cda1695f7fad7bc396093'),
+        ('20', '3', 'acb359dc9b1bcff7e0f1965baa9f3f3dc18eeae99c49f1103c1e2986c0bbeed8'),
+        ('20', '4', 'fd93c74f5ec80689023648cdd12b2c5fb21a3898c81ebc3fa256ef244932562a'),
+        ('20', '5', '8e46d5be28c002f560050a71f4851b01ef45a3eb66ac90d7e23553fae1370e68'),
+        ('20', '6', '8cf9707b3d08ad9242326f02d1861831ad782c9bfb0c46e7b1f0d4640571d5c1'),
+        ('20', '7', '143b6a09f774aeae8b002afffb00839212020139a11873a3a1a34d4a63fa995d'),
+        ('20', '8', 'a6fc6d5c8ba0aad3a8afe44d1539cc299ef78ab53721e28244198fd5425d14ad'),
+        ('20', '9', '5ce6b534bab869b1e9bfefa353d7f578750e54fa72c8c9d74ddf129d993e78cf'),
         ('18', '1', '3cefac9a24ece99176d5d2d58fea2722de3e235be5138a128428b9260fe922ad'),
         ('18', '2', '3a0707a9a59dcbffa765dcf87b68001450095c51b96ec39d21260ba548a2f66a'),
         ('18', '3', '24c2e06f71ae553a408caa3f722254db2cbf1ca4db274542302184e3d6ca7015'),
@@ -94,17 +100,17 @@ def url_for_version(self, version):
               sha256=checksum, level=0, when='@{0}'.format(ver))
 
     # Patch to add ppc64le in config.guess
-    patch('ppc64le.patch', when='@18.20')
+    patch('ppc64le.patch', when='@18: target=ppc64le')
 
     # Patch to add aarch64 in config.guess
-    patch('aarch64.patch', when='@18.20')
+    patch('aarch64.patch', when='@18: target=aarch64')
 
     # Workaround to modify the AmberTools script when using the NVIDIA
     # compilers
-    patch('nvhpc.patch', when='@18.20 %nvhpc')
+    patch('nvhpc.patch', when='@18: %nvhpc')
 
     # Workaround to use NVIDIA compilers to build the bundled Boost
-    patch('nvhpc-boost.patch', when='@18.20 %nvhpc')
+    patch('nvhpc-boost.patch', when='@18: %nvhpc')
 
     variant('mpi', description='Build MPI executables',
             default=True)


Test patch: