예제 #1
0
def test_linecount():
    """Tests the linecount method in utility.
    """
    from matdb.utility import linecount

    assert linecount("temp") == 0

    with open("temp.txt","w+") as f:
        f.write("This is a test file. \n It is rather boring. \n. Thanks for listening.")
    assert linecount("temp.txt") == 3
    remove("temp.txt")
예제 #2
0
    def jobfile(self, rerun=0, recovery=False):
        """Creates the job array file to run each of the sub-configurations in
        this database.
        Args:
            rerun (int): when > 0, recreate the jobfile even if it
              already exists.
            recovery (bool): when True, configure the jobfile to run
              recovery jobs for those that have previously failed. This uses a
              different template and execution path.
        """

        self._expand_sequence()

        if len(self.sequence) == 0:
            if recovery:
                from matdb.utility import linecount
                target = path.join(self.root, "recovery.sh")
                xpath = path.join(self.root, "failures")
                asize = linecount(xpath)
            else:
                target = path.join(self.root, "jobfile.sh")
                xpath = path.join(self.root, "{}.".format(self.prefix))
                asize = len(self.configs)

            if (path.isfile(target) and rerun == 0) or asize == 0:
                return

            # We use the global execution parameters and then any updates
            # locally. We need to add the execution directory (including prefix) and
            # the number of jobs in the array.
            settings = self.database.execution.copy()
            settings.update(self.execution.items())

            settings["set_size"] = self.set_size
            settings["execution_path"] = xpath
            settings["array_size"] = asize - self.set_size

            if "array_limit" in settings and asize < settings["array_limit"]:
                del settings["array_limit"]

            from jinja2 import Environment, PackageLoader
            env = Environment(loader=PackageLoader('matdb', 'templates'))
            if recovery:
                template = env.get_template(settings["template"].replace(
                    "array", "recovery"))
            else:
                template = env.get_template(settings["template"])

            with open(target, 'w') as f:
                f.write(template.render(**settings))
        else:  #pragma: no cover, enumerated database shouldn't take seeds
            for group in self.sequence.values():
                group.jobfile(rerun=rerun, recovery=recovery)
예제 #3
0
파일: md.py 프로젝트: HallLabs/tracy_matdb
    def _xdatcar_ok(self):
        """Determines if the MD run is finished calculating by testing the
        existence of the XDATCAR files with correct number of lines.
        """
        for i, folder in self.configs.items():
            target = path.join(folder, "XDATCAR")
            if path.isfile(target):
                #Make sure we have all the steps we need. There should
                #be at least as many entries as requested configs. We
                #also have the lattice vectors, label and atom counts,
                #which adds 5 lines.
                from matdb.utility import linecount
                minlines = self.nsteps * (self.seed.n + 1)
                nlines = linecount(target)
                if nlines < minlines + 5:
                    return False
            else:
                return False

        return True
예제 #4
0
 def ready(self):
     """Determines if this database is finished calculating by testing the
     existence of the xyz database file in the root folder.
     """
     target = path.join(self.root, "output.xyz")
     result = False
     if path.isfile(target):
         from matdb.utility import linecount
         #We add +2 for the parameter line and the number of atoms.
         #This doesn't work as advertised (it's off by a factor). debug after refactor.
         lpconfig = self.base.atoms.n * np.linalg.det(
             np.array(self.base.supercell).reshape(3, 3)) + 2
         nlines = linecount(target)
         nconfigs = nlines / lpconfig
         result = nconfigs == len(self.configs)
         if not result:
             wmsg = ("Number of structures in `output.xyz` does not match "
                     "number of requested configs. Found {0} configs in"
                     " {1} lines.")
             msg.warn(wmsg.format(nconfigs, nlines))
     return result
예제 #5
0
파일: md.py 프로젝트: HallLabs/tracy_matdb
 def ready(self):
     """Returns True if this database has finished its computations and is
     ready to be used.
     """
     from matdb.utility import linecount
     return linecount(self.subsamples) == self.nsteps * (len(self.strains))