Read COLVAR file using pandas and formatting

Sometimes it is convenient to read the COLVAR file (Plumed output) using pandas as it can act as a first step for machine learning based data analysis e.g. time-series forecasting, clustering, dimensionality reduction etc.

You need to remove the #! FIELDS part from the header. The modified header looks like

time meanfree_sin_chi1_75 meanfree_sin_chi1_76 meanfree_sin_chi1_77 meanfree_sin_chi1_78 meanfree_sin_chi1_79 meanfree_sin_chi1_80 meanfree_sin_chi1_82 meanfree_sin_chi1_83 meanfree_sin_chi1_84 meanfree_cos_chi1_75 meanfree_cos_chi1_76 meanfree_cos_chi1_77 meanfree_cos_chi1_78 meanfree_cos_chi1_79 meanfree_cos_chi1_80 meanfree_cos_chi1_82 meanfree_cos_chi1_83 meanfree_cos_chi1_84 meanfree_sin_chi2_75 meanfree_sin_chi2_76 meanfree_sin_chi2_77 meanfree_sin_chi2_78 meanfree_cos_chi2_75 meanfree_cos_chi2_76 meanfree_cos_chi2_77 meanfree_cos_chi2_78

 0.000000 0.569694 -0.563760 -0.293910 -0.085431 -0.851665 -0.932727 -0.414956 0.906188 -0.022867 0.485136 0.332040 1.086123 0.485252 0.581138 0.141012 0.432328 1.073254 -0.354269 -0.209285 0.913038 1.087512 -0.746633 -0.496575 0.551505 -0.306913 0.522497

Here is the code

import IPython
import IPython.display
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns

from pandas import read_csv

#load dataset

df = pd.read_csv('COLVAR_meanfreechi1chi2', header=0, sep=',', delim_whitespace=True)


#transform to csv format


Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s