Closed bk322 closed 2 years ago
I'm using this:
Legend = []
fp = open(args.xvg)
for i, line in enumerate(fp):
if line.startswith('#') or line.startswith('@'):
if line.startswith('@'):
if re.search('xaxis', line):
xaxis = re.sub('.*"(.+)".*', r'\1', line.strip())
elif re.search('yaxis', line):
yaxis = re.sub('.*"(.+)".*', r'\1', line.strip())
elif re.match(r'@ s', line):
Legend.append(re.sub(r'.*"(.+)".*', r'\1', line.strip()))
else:
break
fp.close()
The issue on startup can be ignored; it just means that you don't have a number of gromacs tools installed that I use (and which I put in the default config file). You could remove them from ~/.gromacswrapper.cfg without harm.
The XVG class does not parse metadata at the moment. We could use code similar to what you posted. If you want to fork GromacsWrapper and implement code like the above I would consider merging your changes into the main development line.
It seems the XVG reader has finally learned to read metadata, names and axis-labels from Gromacs-Generated XVG files. :tada:
However the behaviour is somewhat inconsistent. See for example:
In [1]: import gromacs.formats
...: print(gromacs.__version__)
0.8.2
In [2]: xvg = gromacs.formats.XVG(filename='examples/gmx_energy_temp.xvg')
In [3]: print(xvg.names)
...: print(xvg.metadata)
[]
{}
In [4]: print(xvg.array)
[[ 0. 1. 2. 3. 4. 5. ]
[300.405334 301.206299 300.53598 301.529816 298.039734 300.182587]]
In [5]: print(xvg.names)
...: print(xvg.metadata)
['Temperature']
{'legend': ['on', 'box on', 'loctype view', '0.78, 0.8', 'length 2']}
In [6]:
The first time I access the names and metadata attributes, they are empty, but once I have accessed the array once, they are suddenly populated. :thinking:
Cheers, ostueker (Oliver S.)
The XVGReader does lazy-loading, it only actually reads the file when the array is created.
That's admittedly a bit confusing, especially when it comes to the metadata.
Btw, I probably should have closed this issue when PR #18 was merged, which added some metadata parsing (although not all).
At least some of the metadata are read (added in PR #18). If anything else is missing that you'd really want then please open a new issue. Thank you!
Hi Oliver, today I tried to plot xvg data in matplotlib. I read it with GromacsWrapper -- but can't access xvg metadata:
I need xaxis, yaxis and legend in particular:
I'm using bleeding edge GromacsWrapper, I get a moderate issue on startup:
I don't think it is relevant.