Example #1
0
    def convert_to_csv(self, remove=True):
        """
        This function converts the tab-delimited txt file from Dragon to pandas dataframe.
        Note that this process might require large memory based on the number of data points and features.

        Parameters
        ----------
        remove : bool, optional (default = True)
            if True, the original descriptors file (Dragon_descriptors.txt) will be removed.

        Returns
        -------
        features : pandas DataFrame
            The 2D dataframe of the descriptors. Note that the first two columns are 'No.' and 'NAME'.

        """
        # convert to csv file
        t0 = time.time()
        print("converting output file to csv format ...")
        df = pd.read_csv(self.data_path, sep=None, engine='python')
        # df = df.drop(['No.', 'NAME'], axis=1)

        # execution time
        tmp_str = tot_exec_time_str(t0)

        # remove original tab delimited file
        if remove:
            os.remove(self.data_path)
            self.data_path = None

        print("... conversion completed in %s" % tmp_str)

        return df
Example #2
0
    def run(self):
        t0 = time.time()
        print("running Dragon%i ..." % self.version)
        os_ret = os.system(
            'nohup dragon%sshell -s %s' %
            (self.version, os.path.join(self.output_directory, self.drs_name)))
        if os_ret != 0:
            msg = "Oops, dragon%ishell command didn't work! Are you sure Dragon%i software is installed on your machine?" % (
                self.version, self.version)
            raise ImportError(msg)

        # execution time
        tmp_str = tot_exec_time_str(t0)
        print("... Dragon job completed in %s" % tmp_str)
Example #3
0
def test_exec_time_str():
    time_start = time.time()
    time.sleep(0.5)
    s = tot_exec_time_str(time_start)
    assert int(s[-4]) >= 5
Example #4
0
    def call(self):
        self.refs = {}
        for iblock in self.ImpOrder:
            task = self.cmls[iblock]['task']
            parameters = self.cmls[iblock]['parameters']
            host = parameters.pop('host')
            function = parameters.pop('function')
            start_time = time.time()
            tmp_str = "======= block#%i: (%s, %s)" % (iblock + 1, host,
                                                      function)
            print(tmp_str)
            tmp_str = "| run ...\n"
            print(tmp_str)
            if host == 'sklearn':
                # check methods
                legal_functions = [
                    klass[0] for klass in inspect.getmembers(sklw)
                ]
                if function in legal_functions:
                    self.references(host, function)  # check references
                    self.Base.graph_info[iblock] = (host, function)
                    cml_interface = [
                        klass[1] for klass in inspect.getmembers(sklw)
                        if klass[0] == function
                    ][0]
                    cmli = cml_interface(self.Base, parameters, iblock, task,
                                         function, host)
                    cmli.run()
                else:
                    self.references(host, function)  # check references
                    self.Base.graph_info[iblock] = (host, function)
                    cml_interface = [
                        klass[1] for klass in inspect.getmembers(sklw)
                        if klass[0] == 'automatic_run'
                    ][0]
                    cmli = cml_interface(self.Base, parameters, iblock, task,
                                         function, host)
                    cmli.run()
            elif host == 'chemml':
                # check methods
                legal_functions = [
                    klass[0] for klass in inspect.getmembers(cmlw)
                ]
                # print("legal_functions: ", legal_functions)
                if function not in legal_functions:
                    msg = "@function #%i: couldn't find function '%s' in the module '%s' wrapper" % (
                        iblock, function, host)
                    raise NameError(msg)
                self.references(host, function)  # check references
                self.Base.graph_info[iblock] = (host, function)
                cml_interface = [
                    klass[1] for klass in inspect.getmembers(cmlw)
                    if klass[0] == function
                ][0]
                cmli = cml_interface(self.Base, parameters, iblock, task,
                                     function, host)
                cmli.run()
            elif host == 'pandas':
                # check methods
                legal_functions = [
                    klass[0] for klass in inspect.getmembers(pdw)
                ]
                if function not in legal_functions:
                    msg = "@function #%i: couldn't find function '%s' in the module '%s' wrarpper" % (
                        iblock, function, host)
                    raise NameError(msg)
                self.references(host, function)  # check references
                self.Base.graph_info[iblock] = (host, function)
                cml_interface = [
                    klass[1] for klass in inspect.getmembers(pdw)
                    if klass[0] == function
                ][0]
                cmli = cml_interface(self.Base, parameters, iblock, task,
                                     function, host)
                cmli.run()
            elif host == 'tensorflow':
                # check methods
                legal_functions = [
                    klass[0] for klass in inspect.getmembers(tfw)
                ]
                if function not in legal_functions:
                    msg = "@function #%i: couldn't find function '%s' in the module '%s' wrarpper" % (
                        iblock, function, host)
                    raise NameError(msg)
                self.references(host, function)  # check references
                self.Base.graph_info[iblock] = (host, function)
                cml_interface = [
                    klass[1] for klass in inspect.getmembers(tfw)
                    if klass[0] == function
                ][0]
                cmli = cml_interface(self.Base, parameters, iblock, task,
                                     function, host)
                cmli.run()

            end_time = tot_exec_time_str(start_time)
            tmp_str = "| ... done!"
            print(tmp_str)
            tmp_str = '| ' + end_time
            print(tmp_str)
            tmp_str = "=======\n\n"
            print(tmp_str)
        self._save_references()
        tmp_str = "Total " + tot_exec_time_str(self.Base.start_time)
        print(tmp_str)
        tmp_str = std_datetime_str() + '\n'
        print(tmp_str)