Other
A collection of common functions for basic MD process: supercell, read and write POSCAR, PDF, XYZ, progressbar, replace_in_file, read_ORCA
evaluate_linear_fit_np(x, y)
Evaluate a simple linear fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x |
ndarray
|
Independent variable values. |
required |
y |
ndarray
|
Dependent variable values. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Coefficient of determination (R^2) and mean squared error. |
Source code in m2dtools/other/common.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
pdf_sq_1type(box, natom, type_atom, coors, r_cutoff=10, delta_r=0.01)
Compute pair distribution and structure factors for a single species.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
box |
ndarray
|
Simulation box matrix. |
required |
natom |
int
|
Total number of atoms. |
required |
type_atom |
array - like
|
Atom type identifiers. |
required |
coors |
ndarray
|
Cartesian coordinates. |
required |
r_cutoff |
float
|
Maximum distance for the radial distribution function. |
10
|
delta_r |
float
|
Bin width for the radial distribution function. |
0.01
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray, ndarray, ndarray]
|
Radial positions, pair distribution function, q values and structure factor for the single-species system. |
Source code in m2dtools/other/common.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
read_pos(file_name)
Read a VASP POSCAR structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name |
str
|
Path to the POSCAR file. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray, ndarray, ndarray]
|
Box matrix, atomic species, species counts and Cartesian coordinates. |
Source code in m2dtools/other/common.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
read_xyz_simple(filename)
Read an extended XYZ file. Returns: types : (N,) array of strings coords : (N,3) float array lattice: (3,3) float array (box matrix)
Source code in m2dtools/other/common.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
replace_in_file(file_path_old, file_path_new, old_string, new_string)
Replace text within a file and write the updated copy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path_old |
str
|
Source file to read. |
required |
file_path_new |
str
|
Destination path for the updated content. |
required |
old_string |
str
|
Text to be replaced. |
required |
new_string |
str
|
Replacement text. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Writes |
Source code in m2dtools/other/common.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
supercell(natoms, box0, nx, ny, nz, index0, atom_type0, coors0)
Build a replicated supercell from an orthogonal unit cell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
natoms |
int
|
Number of atoms in the original cell. |
required |
box0 |
ndarray
|
|
required |
nx |
int
|
Replication counts along each lattice vector. |
required |
ny |
int
|
Replication counts along each lattice vector. |
required |
nz |
int
|
Replication counts along each lattice vector. |
required |
index0 |
ndarray
|
Atom indices for the original cell. |
required |
atom_type0 |
ndarray
|
Atom types for the original cell. |
required |
coors0 |
ndarray
|
Cartesian coordinates for the original cell. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
|
Source code in m2dtools/other/common.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
write_pos(file_name, box, a_type, num_type, coors)
Write a VASP POSCAR structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name |
str
|
Destination POSCAR path. |
required |
box |
ndarray
|
|
required |
a_type |
array - like
|
Sequence of element symbols. |
required |
num_type |
array - like
|
Number of atoms for each element. |
required |
coors |
ndarray
|
Cartesian coordinates for all atoms. |
required |
Returns:
| Type | Description |
|---|---|
None
|
The POSCAR file is written to |
Source code in m2dtools/other/common.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
write_xyz_file(atom_types, coordinates, filename, comment='')
Write an XYZ file from atom types and coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atom_types |
list[str]
|
Atom types or symbols. |
required |
coordinates |
list[tuple[float, float, float]]
|
Cartesian coordinates for each atom. |
required |
filename |
str
|
Path to the output XYZ file. |
required |
comment |
str
|
Comment to include on the second line of the file. |
""
|
Returns:
| Type | Description |
|---|---|
None
|
The XYZ file is written to |
Source code in m2dtools/other/common.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
Tools for reading and writing .gro files
gro2pos(posfile, grofile)
Convert a .gro file to a POSCAR structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
posfile |
str
|
Destination POSCAR file path. |
required |
grofile |
str
|
Source |
required |
Returns:
| Type | Description |
|---|---|
None
|
Writes the POSCAR representation to |
Source code in m2dtools/other/tools_gro.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
read_gro(file_name)
Read a GROMACS .gro file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name |
str
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, int, ndarray, ndarray]
|
Box matrix, atom count, atom types and coordinates. |
Source code in m2dtools/other/tools_gro.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
read_gro_multi(gro_file)
Read multiple frames from a concatenated .gro file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gro_file |
str
|
Path to the multi-frame |
required |
Returns:
| Type | Description |
|---|---|
tuple[list, list]
|
List of frame tuples |
Source code in m2dtools/other/tools_gro.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
write_gro(filename, box, natom, type_atom, coors)
Write a GROMACS .gro file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename |
str
|
Output file name without extension. |
required |
box |
ndarray
|
|
required |
natom |
int
|
Number of atoms. |
required |
type_atom |
array - like
|
Atom type identifiers. |
required |
coors |
ndarray
|
Cartesian coordinates for each atom. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Writes |
Source code in m2dtools/other/tools_gro.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |