Forum Navigation
You need to log in to create posts and topics.

PythonInterface: getting column names for output

Hello,
I just started using the python interface and my goal is to compute the radial distribution function and output to a .txt, similar to what ovito does in the software. Getting the data was quite easy and straightforward but what I am struggling with now is to get the correct column names for the output, namely the element pairs.

This is my code:

#!/usr/bin/env python3
from ovito.io import import_file, export_file
from ovito.modifiers import CoordinationAnalysisModifier
import numpy

pipeline = import_file("POSCAR")
modifier = CoordinationAnalysisModifier(cutoff = 10.0, number_of_bins  = 200, partial = True)

pipeline.modifiers.append(modifier)
rdfdata = pipeline.compute()

numpy.savetxt("rdfout.txt", rdfdata.tables['coordination-rdf'].xy())

The output I get is just the plain table of numerical data, but what I'd like to have is similar to what's in the header of the output file generated by OVITO:

# Radial distribution function (200 data points):
# "Pair separation distance" Al-Al Al-C Al-Nb Al-N C-C C-Nb C-N Nb-Nb Nb-N N-N
0.025 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.075 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.125 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.175 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

so maybe something along the lines of :

A-A A-B A-C B-B B-C C-C
1      1      1      1       1      1
2     2      2     2       2     2

Thank you very much for your help.

Hi Alexander,

in principle you can use OVITO's export_file() functionality 'txt/table'to export any Data Table in the DataCollection, see https://www.ovito.org/docs/current/python/modules/ovito_data.php#ovito.data.DataTable.

You can use:

export_file(pipeline, 'rdfout.txt', 'txt/table', key='coordination-rdf')

That way you don't have to use numpy.savetxt() and don't need to define the header yourself.

-Constanze

Constanze's solution is definitely preferred. But for the sake of completeness, let me add that you could access the list of table column names, i.e. the names of partial RDF functions that are displayed in the GUI, as follows:

data = pipeline.compute()
rdf_table = data.tables['coordination-rdf']
print(rdf_table.y.component_names)

Note, however, that Property.component_names being used here is an undocumented field, which is not in the API documentation yet.

Thank you very much, your help is much appreciated!
I tried both methods, but although Constanze's solution was exactly what I was asking for, I think I'll use Alexander's solution because it allows me to directly continue with an array for further processing, thus avoiding reading and writing files all the time.

Thanks a lot !!