|
27 | 27 | import os |
28 | 28 | from functools import partial |
29 | 29 | from glob import glob |
| 30 | +from typing import TextIO |
30 | 31 |
|
31 | 32 | import attrs |
32 | 33 | import numpy as np |
@@ -83,19 +84,27 @@ def dump(self, atpos: ArrayLike, cell_lengths: ArrayLike): |
83 | 84 |
|
84 | 85 | def dump_each(self, atpos: ArrayLike, cell_lengths: ArrayLike): |
85 | 86 | """Write a snapshot to the PDB file without considering `self.stride`.""" |
| 87 | + with open(self.path_pdb, "a") as fh: |
| 88 | + self._dump_low(fh, atpos, cell_lengths) |
| 89 | + |
| 90 | + def dump_single(self, path_pdb: str, atpos: ArrayLike, cell_lengths: ArrayLike): |
| 91 | + """Dump a single snapshot with the same settings to a different file.""" |
| 92 | + with open(path_pdb, "w") as fh: |
| 93 | + self._dump_low(fh, atpos, cell_lengths) |
| 94 | + |
| 95 | + def _dump_low(self, fh: TextIO, atpos: ArrayLike, cell_lengths: ArrayLike): |
86 | 96 | atpos = parse_atpos(atpos, len(self.atnums)) |
87 | 97 | cell_lengths = parse_cell_lengths(cell_lengths) |
88 | | - with open(self.path_pdb, "a") as fh: |
89 | | - a, b, c = cell_lengths * self.to_angstrom |
90 | | - print(f"CRYST1{a:9.3f}{b:9.3f}{c:9.3f} 90.00 90.00 90.00 P 1 1", file=fh) |
91 | | - for i, (x, y, z) in enumerate(atpos * self.to_angstrom): |
92 | | - symbol = SYMBOLS[self.atnums[i] - 1] |
93 | | - print( |
94 | | - f"HETATM{i+1:5d} {symbol:2s} ATM 1 {x:8.3f}{y:8.3f}{z:8.3f}" |
95 | | - f" 1.00 1.00 {symbol:2s}", |
96 | | - file=fh, |
97 | | - ) |
98 | | - print("END", file=fh) |
| 98 | + a, b, c = cell_lengths * self.to_angstrom |
| 99 | + print(f"CRYST1{a:9.3f}{b:9.3f}{c:9.3f} 90.00 90.00 90.00 P 1 1", file=fh) |
| 100 | + for i, (x, y, z) in enumerate(atpos * self.to_angstrom): |
| 101 | + symbol = SYMBOLS[self.atnums[i] - 1] |
| 102 | + print( |
| 103 | + f"HETATM{i+1:5d} {symbol:2s} ATM 1 {x:8.3f}{y:8.3f}{z:8.3f}" |
| 104 | + f" 1.00 1.00 {symbol:2s}", |
| 105 | + file=fh, |
| 106 | + ) |
| 107 | + print("END", file=fh) |
99 | 108 |
|
100 | 109 |
|
101 | 110 | @attrs.define |
|
0 commit comments