Révision f8c4eafe modules/formats.py
b/modules/formats.py | ||
---|---|---|
99 | 99 |
|
100 | 100 |
Given a run_type ('isolated', 'screening' or 'refinement') directory |
101 | 101 |
containing different subdirectories with finished calculations in every |
102 |
subdirectory, it reads the coordinates inside each subdirectory according to |
|
103 |
the specified code and returns a list of objects required. |
|
102 |
subdirectory, it reads, from each subirectory, the final coordinates |
|
103 |
resulting from the calculation and returns a list of objects adequate to the |
|
104 |
required library. |
|
104 | 105 |
|
105 |
@param code: the code that produced the coordinates out of a calculation.
|
|
106 |
@param code: the code that produced the calculation results files.
|
|
106 | 107 |
@param run_type: the type of calculation (and also the name of the folder) |
107 | 108 |
containing the calculation subdirectories. |
108 |
@param req: The required object type to make the list of. |
|
109 |
@param req: The required library object type to make the list of (eg. rdkit, |
|
110 |
ase) |
|
109 | 111 |
@return: list of collection-of-atoms objects. (rdkit.Mol, ase.Atoms, etc.) |
110 | 112 |
""" |
111 | 113 |
import os |
... | ... | |
116 | 118 |
return [adapt_format(req, f'{run_type}/{conf}/{fil}') |
117 | 119 |
for conf in os.listdir(run_type) |
118 | 120 |
for fil in os.listdir(f"{run_type}/{conf}") if pattern in fil] |
121 |
|
|
122 |
|
|
123 |
def read_energies(code, run_type): |
|
124 |
"""Reads the energies resulting from finished calculations. |
|
125 |
|
|
126 |
Given a run_type ('isolated', 'screening' or 'refinement') directory |
|
127 |
containing different subdirectories with finished calculations in every |
|
128 |
subdirectory, it reads the final energies of calculations inside each |
|
129 |
subdirectory. |
|
130 |
|
|
131 |
@param code: the code that produced the calculation results files. |
|
132 |
@param run_type: the type of calculation (and also the name of the folder) |
|
133 |
containing the calculation subdirectories. |
|
134 |
@return: list of energies |
|
135 |
""" |
|
136 |
import os |
|
137 |
import numpy as np |
|
138 |
from utilities import tail |
|
139 |
|
|
140 |
energies = [] |
|
141 |
if code == 'cp2k': |
|
142 |
pattern = '-pos-1.xyz' |
|
143 |
for conf in os.listdir(run_type): |
|
144 |
for fil in os.listdir(f"{run_type}/{conf}"): |
|
145 |
if pattern in fil: |
|
146 |
traj_fh = open(f"{run_type}/{conf}/{fil}", 'rb') |
|
147 |
num_atoms = int(traj_fh.readline().strip()) |
|
148 |
last_geo = tail(traj_fh, num_atoms + 2).splitlines() |
|
149 |
for line in last_geo: |
|
150 |
if 'E =' in line: |
|
151 |
energies.append(float(line.split('E =')[1])) |
|
152 |
|
|
153 |
return np.array(energies) |
Formats disponibles : Unified diff