4
$\begingroup$

Is there any post processing tools by which I can get average value of lattice parameters from cell trajectory? For example: I ran 'vc-cp' (CPMD) in quantum espresso (for Silicon) and Si.cel file is created by CPMD, which contains lattice parameters at every step. I have used 10000 steps with interval of 10.

10      0.00120944  
9.49859   -2.24446   1.37072    
-2.29735   8.74994   -1.97679  
1.51824    -2.6148   9.66447  
...  
...  
...  
10000   0.133034  
9.48745   -2.224956   1.38545    
-2.28475  8.748565    -1.98745  
1.52478   -2.64752    9.67304  

How can I get average lattice parameters from that si.cel trajectory?

Thanks

$\endgroup$
2
  • $\begingroup$ So, you have let's say 1000 of cell parameters (each of them is like a 3*3 matrix) in the given format and you want another matrix whose elements are the average of corresponding elements of all the matrices? $\endgroup$ Commented Jun 10 at 16:27
  • $\begingroup$ Yes, you are right! $\endgroup$ Commented Jun 10 at 16:34

1 Answer 1

3
$\begingroup$

This python code should work. It will print the average lattice parameters from the file Si.cel.

import numpy as np

matrices = []
    
with open("Si.cel", 'r') as file:
    lines = file.readlines()
    for i in range(0, len(lines), 4):
        matrix = np.array([list(map(float, lines[i + j + 1].split())) for j in range(3)])
        matrices.append(matrix)
   
print(np.mean(matrices, axis=0))
$\endgroup$
2
  • $\begingroup$ Thank you so much!!! That means I have to develop code to find out any average properties (e.g. Temp, Pressure, Lattice Parameters etc) from the MD output trajectory files. I thought there might be a post processing tool that can handle it. Thank you again for your time. $\endgroup$ Commented Jun 11 at 0:24
  • 1
    $\begingroup$ @MuhammadHasan There might be some post-processing tools but I don't know. In this type of cases, simple python or bash script (awk+grep+bc) should be enough. Tools such as ChatGPT or copilot can be very helpful to generate this type of code snippet. The above code is generated by GitHub copilot with very little modification. $\endgroup$ Commented Jun 11 at 4:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .