Example #1
0
 def calc_new(self, coords, dirname):
     try:
         from forcebalance.gmxio import GMX
     except ImportError:
         raise ImportError(
             "ForceBalance is needed to compute energies and gradients using Gromacs."
         )
     if not os.path.exists(dirname): os.makedirs(dirname)
     try:
         Gro = Molecule("conf.gro")
         Gro.xyzs[0] = coords.reshape(-1, 3) * bohr2ang
         cwd = os.getcwd()
         shutil.copy2("topol.top", dirname)
         shutil.copy2("shot.mdp", dirname)
         os.chdir(dirname)
         Gro.write("coords.gro")
         G = GMX(coords="coords.gro",
                 gmx_top="topol.top",
                 gmx_mdp="shot.mdp")
         EF = G.energy_force()
         Energy = EF[0, 0] / eqcgmx
         Gradient = EF[0, 1:] / fqcgmx
         os.chdir(cwd)
     except (OSError, IOError, RuntimeError, subprocess.CalledProcessError):
         raise GromacsEngineError
     return {'energy': Energy, 'gradient': Gradient}
Example #2
0
 def setup_class(cls):
     """
     setup any state specific to the execution of the given class (which usually contains tests).
     """
     super(TestAmber99SB, cls).setup_class()
     tinkerpath = which('testgrad')
     # try to find mdrun_d or gmx_d
     # gmx should be built with config -DGMX_DOUBLE=ON
     gmxpath = which('mdrun_d') or which('gmx_d')
     gmxsuffix = '_d'
     # Tests will FAIL if use single precision gromacs
     # gmxpath = which('mdrun') or which('gmx')
     # gmxsuffix = ''
     # self.logger.debug("\nBuilding options for target...\n")
     cls.cwd = os.path.dirname(os.path.realpath(__file__))
     os.chdir(os.path.join(cls.cwd, "files", "amber_alaglu"))
     cls.tmpfolder = os.path.join(cls.cwd, "files", "amber_alaglu", "temp")
     if not os.path.exists(cls.tmpfolder):
         os.makedirs(cls.tmpfolder)
     os.chdir(cls.tmpfolder)
     for i in [
             "topol.top", "shot.mdp", "a99sb.xml", "a99sb.prm", "all.gro",
             "all.arc", "AceGluNme.itp", "AceAlaNme.itp", "a99sb.itp"
     ]:
         os.system("ln -fs ../%s" % i)
     cls.engines = OrderedDict()
     # Set up GMX engine
     if gmxpath != '':
         cls.engines['GMX'] = GMX(coords="all.gro",
                                  gmx_top="topol.top",
                                  gmx_mdp="shot.mdp",
                                  gmxpath=gmxpath,
                                  gmxsuffix=gmxsuffix)
     else:
         logger.warn("GROMACS cannot be found, skipping GMX tests.")
     # Set up TINKER engine
     if tinkerpath != '':
         cls.engines['TINKER'] = TINKER(coords="all.arc",
                                        tinker_key="alaglu.key",
                                        tinkerpath=tinkerpath)
     else:
         logger.warn("TINKER cannot be found, skipping TINKER tests.")
     # Set up OpenMM engine
     try:
         try:
             import openmm
         except ImportError:
             import simtk.openmm
         cls.engines['OpenMM'] = OpenMM(coords="all.gro",
                                        pdb="conf.pdb",
                                        ffxml="a99sb.xml",
                                        platname="Reference",
                                        precision="double")
     except:
         logger.warn("OpenMM cannot be imported, skipping OpenMM tests.")
Example #3
0
 def calc_new(self, coords, dirname):
     if not os.path.exists(dirname): os.makedirs(dirname)
     Gro = Molecule("conf.gro")
     Gro.xyzs[0] = coords.reshape(-1, 3) * 0.529
     cwd = os.getcwd()
     shutil.copy2("topol.top", dirname)
     shutil.copy2("shot.mdp", dirname)
     os.chdir(dirname)
     Gro.write("coords.gro")
     G = GMX(coords="coords.gro", gmx_top="topol.top", gmx_mdp="shot.mdp")
     EF = G.energy_force()
     Energy = EF[0, 0] / eqcgmx
     Gradient = EF[0, 1:] / fqcgmx
     os.chdir(cwd)
     return Energy, Gradient
Example #4
0
 def setUp(self):
     tinkerpath = which('testgrad')
     gmxsuffix = '_d'
     gmxpath = which('mdrun' + gmxsuffix)
     self.logger.debug("\nBuilding options for target...\n")
     self.cwd = os.getcwd()
     os.chdir(os.path.join(os.getcwd(), "test", "files", "amber_alaglu"))
     if not os.path.exists("temp"): os.makedirs("temp")
     os.chdir("temp")
     for i in [
             "topol.top", "shot.mdp", "a99sb.xml", "a99sb.prm", "all.gro",
             "all.arc", "AceGluNme.itp", "AceAlaNme.itp", "a99sb.itp"
     ]:
         os.system("ln -fs ../%s" % i)
     self.engines = OrderedDict()
     # Set up GMX engine
     if gmxpath != '':
         self.engines['GMX'] = GMX(coords="all.gro",
                                   gmx_top="topol.top",
                                   gmx_mdp="shot.mdp",
                                   gmxpath=gmxpath,
                                   gmxsuffix=gmxsuffix)
     else:
         logger.warn("GROMACS cannot be found, skipping GMX tests.")
     # Set up TINKER engine
     if tinkerpath != '':
         self.engines['TINKER'] = TINKER(coords="all.arc",
                                         tinker_key="alaglu.key",
                                         tinkerpath=tinkerpath)
     else:
         logger.warn("TINKER cannot be found, skipping TINKER tests.")
     # Set up OpenMM engine
     openmm = False
     try:
         import simtk.openmm
         openmm = True
     except:
         logger.warn("OpenMM cannot be imported, skipping OpenMM tests.")
     if openmm:
         self.engines['OpenMM'] = OpenMM(coords="all.gro",
                                         pdb="conf.pdb",
                                         ffxml="a99sb.xml",
                                         platname="Reference",
                                         precision="double")
     self.addCleanup(os.system, 'cd .. ; rm -rf temp')