-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
54 lines (40 loc) · 1.4 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os.path as op
import numpy as np
import pandas as pd
def read_plumed_file(filename, cv_columns=None, bias_column=None):
"""
Read PLUMED output files into pandas DataFrame.
Column names are parsed from the header of the Plumed file (e.g. COLVAR or HILLS)
and indices are taken from the time column of the Plumed file.
Parameters
----------
filename : string
Name of the plumed file that contains collective variable data
(e.g. HILLS or COLVAR).
Returns
-------
data : pd.DataFrame
Pandas DataFrame with column names parsed from CV/bias labels in the plumed
file header and time column used for the index.
Examples
--------
Read COLVAR file from a MetaD simulation into a DataFrame named metad_traj.
>>> metad_traj = read_plumed_file('COLVAR')
>>> metad_traj.head()
# todo: finish example with output
"""
if filename is None:
return None
filename = op.abspath(filename)
with open(filename, "r") as f:
header = f.readline().strip().split(" ")[2:]
data = pd.read_csv(
filename, comment="#", names=header, delimiter="\s+", index_col=0
)
if cv_columns is None and bias_column is None:
return data
if bias_column is None:
return data[cv_columns]
if cv_columns is None:
return data[bias_column]
return data[cv_columns], data[bias_column]