Beispiel #1
0
    def _getmeans(self):
        # called by fit_to_reference and _do_iteration
        # calls map_all()
        # analyses the outputs and returns dG* and dG0 means
        # raises QMapperError on total failure

        self.mapall(_supress_info=True)
        for (qfo, err) in six.iteritems(self.failed):
            logger.info("Failed to map '{}': {}".format(qfo, err))

        if not self.mapped:
            raise QMapperError("All directories failed to map! Try changing "
                               "the initial-guess values (Hij and alpha) "
                               "or step_size... Also, check the mapping "
                               "parameters (skip, bins, ...).")

        dga, dg0 = [], []
        for mapdir, (_, qfo_str) in six.iteritems(self.mapped):
            try:
                qfo = QFepOutput(qfo_str)
                dga.append(qfo.part3.dga)
                dg0.append(qfo.part3.dg0)
            except QFepOutputError as error_msg:
                logger.info("Failed to analyse '{}': {}"
                            "".format(mapdir, error_msg))
            except Exception as error_msg:
                logger.warning("Uncaught exception when analysing '{}': {}"
                               "".format(mapdir, error_msg))

        if not dga or not dg0:
            raise QMapperError("All directories failed to analyse! Try "
                               "changing the initial-guess values (Hij and "
                               "alpha) or step_size...")
        return stats.mean(dga), stats.mean(dg0)
Beispiel #2
0
    def details(self):

        fails = "\n".join(["{}: {}".format(md, e) for md, e in \
                                                 six.iteritems(self.failed)])

        qfep_version = "Unknown, likely ancient"
        for _, qfep_out in self.mapped.values():
            try:
                qfo = QFepOutput(qfep_out)
            except Exception:
                pass
            else:
                qfep_version = qfo.header.qfep_version
                break

        parms_str = "\n".join(["{:<15} {:>15}".format(prm, self.parms[prm]) \
                for prm in sorted(self.parms)])
        mapdirs = ", ".join(self._mapdirs)
        outstr = """
------------------------------- Mapping details -------------------------------
# Mapped with: Qtools ({version}), Qfep ({qfep_version})
# Qfep path: {qfep_exec}
# Work dir: {cwd}
# Date: {date}

# Parms:
{parms}

# Directories:
{dirs}

# Fails:
{fails}
-------------------------------------------------------------------------------
""".format(version=__version__,
           cwd=os.getcwd(),
           date=time.ctime(),
           parms=parms_str,
           fails=fails or "None",
           dirs=mapdirs,
           qfep_version=qfep_version,
           qfep_exec=os.path.abspath(self._qfep.qfep_exec))

        return outstr
Beispiel #3
0
    def details(self):

        fails = "\n".join(["{}: {}".format(md, e) for md, e in \
                                                 self.failed.iteritems()])

        qfep_version = "Unknown, likely ancient"
        for _, qfep_out in self.mapped.values():
            try:
                qfo = QFepOutput(qfep_out)
            except Exception:
                pass
            else:
                qfep_version = qfo.header.qfep_version
                break

        mapdirs = ", ".join(self._mapdirs)
        outstr = """
------------------------------- Mapping details -------------------------------
# Mapped with: Qtools ({version}), Qfep ({qfep_version})
# Qfep path: {qfep_exec}
# Work dir: {cwd}
# Date: {date}
# CMDline: {cmdline}

Directories:
{dirs}

Input:
{inp_parms}

Fails:
{fails}
-------------------------------------------------------------------------------
""".format(version=__version__,
           cwd=os.getcwd(),
           date=time.ctime(),
           inp_parms=self.input_parms_str,
           cmdline=" ".join(sys.argv),
           fails=fails or "None",
           dirs=mapdirs,
           qfep_version=qfep_version,
           qfep_exec=os.path.abspath(self._qfep.qfep_exec))

        return outstr
Beispiel #4
0
    def __init__(self,
                 qfep_outputs,
                 lra_lambdas=None,
                 _parent=None,
                 _subcalc_key=None):

        self._qfep_outputs = sorted(set(qfep_outputs))
        self._lra_lambdas = lra_lambdas
        self._parent = _parent
        self._subcalc_key = _subcalc_key

        self.qfos = ODict()
        self.dgas = ODict()
        self.dg0s = ODict()
        self.dgs_fep = ODict()
        self.lras = ODict()
        self.failed = ODict()
        self.failed_dg = ODict()
        self.sub_calcs = ODict()

        # main calculation (not subcalc)
        if self._parent == None:
            # check if the files exist and if they parse
            for qfep_output in self._qfep_outputs:
                if isinstance(qfep_output, basestring):
                    try:
                        qfep_out_string = open(qfep_output, "r").read()
                    except IOError as error_msg:
                        self.failed[qfep_output] = error_msg
                        continue
                    else:
                        qfep_out_name = qfep_output
                else:
                    qfep_out_name, qfep_out_string = qfep_output

                try:
                    qfo = QFepOutput(qfep_out_string)
                except QFepOutputError as error_msg:
                    self.failed[qfep_out_name] = error_msg
                except Exception as error_msg:
                    self.failed[qfep_out_name] = "UNCAUGHT EXCEPTION: {}"\
                                                 "".format(error_msg)
                else:
                    self.qfos[qfep_out_name] = qfo
        # exctract data (exclusion or QCP) from parent's sub_calcs
        else:
            self.qfos_failed = self._parent.failed
            for p_qfo_key, p_qfo in self._parent.qfos.iteritems():
                if self._subcalc_key in p_qfo.sub_calcs:
                    self.qfos[p_qfo_key] = p_qfo.sub_calcs[self._subcalc_key]

        # get dG_FEP, dGa, dG0, LRAs
        for qfep_output, qfo in self.qfos.iteritems():
            self.dgs_fep[qfep_output] = qfo.part1.dg
            try:
                dga = qfo.part3.dga
                dg0 = qfo.part3.dg0
                self.dgas[qfep_output] = dga
                self.dg0s[qfep_output] = dg0
                if qfo.part3.warning:
                    logger.warning("{}: {}".format(qfep_output,
                                                   qfo.part3.warning))
            except QFepOutputError as error_msg:
                self.failed_dg[qfep_output] = error_msg
            except Exception as error_msg:
                self.failed_dg[qfep_output] = "UNCAUGHT EXCEPTION: {}"\
                                              "".format(error_msg)
            # get LRA energies or log if fails (3 states, weird data)
            if self._lra_lambdas != None:
                try:
                    lra = qfo.part0.calc_lra(self._lra_lambdas[0],
                                             self._lra_lambdas[1])
                except Exception as e:
                    logger.warning("LRA failed on '{}': {}"
                                   "".format(qfep_output, e))
                else:
                    self.lras[qfep_output] = lra

            # add sub_calcs to self.sub_calcs, if they exist
            for subcalc_key in qfo.sub_calcs:
                if subcalc_key not in self.sub_calcs:
                    subqaf = QAnalyseFeps(self._qfep_outputs,
                                          self._lra_lambdas,
                                          _parent=self,
                                          _subcalc_key=subcalc_key)
                    self.sub_calcs[subcalc_key] = subqaf
Beispiel #5
0
 def test_bad_output(self):
     with pytest.raises(QFepOutputError):
         QFepOutput(open("data/qcalc.out.1", "r").read())
Beispiel #6
0
 def qfo2(self):
     qfo_str = open("data/qfep.out.2", "r").read()
     return QFepOutput(qfo_str)