예제 #1
0
def process_log(log_file):
    """
    Gather key info from log file
    @param log_file: name of log file
    @return: lists of dicts of key data extracted; 1 dict per timestep and/or summary
    """
    result_list = []
    file_root = get_fname_root(log_file)

    with open(log_file) as l_file:
        reading_data = False
        result_dict = {}
        for line in l_file:
            line = line.strip()
            if RUN_PAT.match(line):
                reading_data = True
                result_dict[FILE_NAME] = file_root
            elif reading_data:
                if ENERGY_PAT.match(line):
                    s_line = line.split()
                    result_dict[TIMESTEP] = int(s_line[1])
                    result_dict[E_DIHED] = float(s_line[4])
                    result_list.append(dict(result_dict))

    return result_list
예제 #2
0
 def testGetRootName(self):
     """
     Check for prefix addition.
     """
     root_name = get_fname_root(ORIG_WHAM_PATH)
     self.assertEqual(root_name, ORIG_WHAM_ROOT)
     self.assertNotEqual(root_name, ORIG_WHAM_FNAME)
     self.assertNotEqual(root_name, ORIG_WHAM_PATH)
예제 #3
0
def process_log(log_file):
    """
    Gather key info from lammps log file
    @param log_file: name of log file
    @return: lists of dicts of key data extracted; 1 dict per timestep
    """
    result_list = []
    file_root = get_fname_root(log_file)

    with open(log_file) as l_file:
        reading_steps = False
        result_dict = {}
        for line in l_file:
            line = line.strip()
            if STEP_PAT.match(line):
                reading_steps = True
                result_dict[FILE_NAME] = file_root
                result_dict[TIMESTEP] = int(line.split()[2])
            elif reading_steps:
                if len(line) == 0:
                    break
                s_line = line.split()
                if s_line[0] == TOTENG:
                    for key_id, key in enumerate([TOTENG, KINENG, TEMP]):
                        result_dict[key] = float(s_line[2 + key_id * 3])
                elif s_line[0] == POTENG:
                    for key_id, key in enumerate([POTENG, E_BOND, E_ANGL]):
                        result_dict[key] = float(s_line[2 + key_id * 3])
                elif s_line[0] == E_DIHED:
                    for key_id, key in enumerate([E_DIHED, E_IMPRO, E_VDWL]):
                        result_dict[key] = float(s_line[2 + key_id * 3])
                elif s_line[0] == E_COUL:
                    for key_id, key in enumerate([E_COUL, E_LONG, PRESS]):
                        result_dict[key] = float(s_line[2 + key_id * 3])
                    result_list.append(dict(result_dict))
                else:
                    # when stop matching, done reading file (either by normal or abnormal termination)
                    break

    return result_list