PyMSDump 0.1.1__cp38-cp38-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- PyMSDump/MSTrj.py +165 -0
- PyMSDump/__init__.py +0 -0
- PyMSDump_.cp38-win_amd64.pyd +0 -0
- pymsdump-0.1.1.dist-info/METADATA +113 -0
- pymsdump-0.1.1.dist-info/RECORD +7 -0
- pymsdump-0.1.1.dist-info/WHEEL +5 -0
- pymsdump-0.1.1.dist-info/top_level.txt +2 -0
PyMSDump/MSTrj.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
from PyMSDump_ import TrajLoad
|
|
2
|
+
from enum import IntEnum, auto, unique
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Iterator, Union
|
|
5
|
+
import numpy as np
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
* Materials Studio .trj use below units:
|
|
10
|
+
* All times are in ps.
|
|
11
|
+
* All energies are in kcal mol-1.
|
|
12
|
+
* All pressure and stress values are in GPa.
|
|
13
|
+
* All volumes are in Å3.
|
|
14
|
+
* All coordinates are in Å.
|
|
15
|
+
* All velocities are in Å ps-1.
|
|
16
|
+
* All forces are in kcal mol-1 Å-1.
|
|
17
|
+
* All temperatures are in K.
|
|
18
|
+
* All logical values are stored as integers (0=FALSE, not 0=TRUE).
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class Frame:
|
|
23
|
+
""" A frame structure in a trajectory
|
|
24
|
+
Attributes:
|
|
25
|
+
step (int): current step
|
|
26
|
+
time (float): current time, ps
|
|
27
|
+
positions (np.ndarray): Atom positions in Å
|
|
28
|
+
velocities (Union[np.ndarray, None]): Atom velocities in Å ps-1
|
|
29
|
+
forces (Union[np.ndarray, None]): Atoms forces in kcal mol-1 Å-1
|
|
30
|
+
box (np.ndarray): The converted lower triangular simulation box (same as .gro but unit is Angstrom)。
|
|
31
|
+
crystal (np.ndarray): pdb crystal, unit is angle and angstrom
|
|
32
|
+
ener (np.ndarray): energy information
|
|
33
|
+
pvol (np.ndarray): pressure and volume information
|
|
34
|
+
hasV (bool): if has velocity
|
|
35
|
+
hasF (bool): if has force
|
|
36
|
+
"""
|
|
37
|
+
step: int
|
|
38
|
+
time: float
|
|
39
|
+
positions: np.ndarray
|
|
40
|
+
velocities: Union[np.ndarray, None]
|
|
41
|
+
forces: Union[np.ndarray, None]
|
|
42
|
+
box: np.ndarray
|
|
43
|
+
crystal: np.ndarray
|
|
44
|
+
ener: np.ndarray
|
|
45
|
+
pvol: np.ndarray
|
|
46
|
+
hasV: bool
|
|
47
|
+
hasF: bool
|
|
48
|
+
|
|
49
|
+
@unique
|
|
50
|
+
class EnergyType(IntEnum):
|
|
51
|
+
Temp=0 # must from 0
|
|
52
|
+
AvgTemp=auto()
|
|
53
|
+
TimeStep=auto()
|
|
54
|
+
InitialTemp=auto()
|
|
55
|
+
FinalTemp=auto()
|
|
56
|
+
TotalPE=auto()
|
|
57
|
+
BondE=auto()
|
|
58
|
+
AngleE=auto()
|
|
59
|
+
TorsionE=auto()
|
|
60
|
+
InversionE=auto()
|
|
61
|
+
vdWE=auto()
|
|
62
|
+
ElectrostaticE=auto()
|
|
63
|
+
HBondE=auto()
|
|
64
|
+
ConstraintE=auto()
|
|
65
|
+
UreyBradleyE=auto()
|
|
66
|
+
ThreeBodyE=auto()
|
|
67
|
+
TotalCrossTermE=auto()
|
|
68
|
+
BendBendE=auto()
|
|
69
|
+
StretchStretchE=auto()
|
|
70
|
+
StretchBendStretchE=auto()
|
|
71
|
+
StretchTorsionStretchE=auto()
|
|
72
|
+
BendTorsionBendE=auto()
|
|
73
|
+
TorsionBendBendE=auto()
|
|
74
|
+
SeperatedStretchStretchE=auto()
|
|
75
|
+
TorsionStretchE=auto()
|
|
76
|
+
InversionInversionE=auto()
|
|
77
|
+
UserE=auto()
|
|
78
|
+
TotalInternalE=auto()
|
|
79
|
+
TotalNonBondE=auto()
|
|
80
|
+
AvgTotalPE=auto()
|
|
81
|
+
AvgBondE=auto()
|
|
82
|
+
AvgAngleE=auto()
|
|
83
|
+
AvgTorsionE=auto()
|
|
84
|
+
AvgInversionE=auto()
|
|
85
|
+
AvgvdWE=auto()
|
|
86
|
+
AvgElectrostaticE=auto()
|
|
87
|
+
AvgHBondE=auto()
|
|
88
|
+
AvgConstraintE=auto()
|
|
89
|
+
AvgUreyBradleyE=auto()
|
|
90
|
+
AvgThreeBodyE=auto()
|
|
91
|
+
AvgTotalCrossTermE=auto()
|
|
92
|
+
AvgBendBendE=auto()
|
|
93
|
+
AvgStretchStretchE=auto()
|
|
94
|
+
AvgStretchBendStretchE=auto()
|
|
95
|
+
AvgStretchTorsionStretchE=auto()
|
|
96
|
+
AvgBendTorsionBendE=auto()
|
|
97
|
+
AvgTorsionBendBendE=auto()
|
|
98
|
+
AvgSeperatedStretchStretchE=auto()
|
|
99
|
+
AvgTorsionStretchE=auto()
|
|
100
|
+
AvgInversionInversionE=auto()
|
|
101
|
+
AvgUserE=auto()
|
|
102
|
+
AvgTotalInternalE=auto()
|
|
103
|
+
AvgTotalNonBondE=auto()
|
|
104
|
+
TotalE=auto()
|
|
105
|
+
TotalKE=auto()
|
|
106
|
+
AvgTotalE=auto()
|
|
107
|
+
AvgTotalKE=auto()
|
|
108
|
+
|
|
109
|
+
@unique
|
|
110
|
+
class PressVolType(IntEnum):
|
|
111
|
+
Press = 0 # must from 0
|
|
112
|
+
Volume=auto()
|
|
113
|
+
TotalPV=auto()
|
|
114
|
+
KineticStrsPV=auto()
|
|
115
|
+
PotentialStrsPV=auto()
|
|
116
|
+
GyrationRadius=auto()
|
|
117
|
+
AvgPress=auto()
|
|
118
|
+
AvgVolume=auto()
|
|
119
|
+
AvgTotalPV=auto()
|
|
120
|
+
AvgKineticStrsPV=auto()
|
|
121
|
+
AvgPotentialStrsPV=auto()
|
|
122
|
+
AvgGyrationRadius=auto()
|
|
123
|
+
|
|
124
|
+
class MSTrjReader:
|
|
125
|
+
def __init__(self, ftrj:str, fpdb:str):
|
|
126
|
+
self.trajectory = TrajLoad(ftrj, fpdb)
|
|
127
|
+
self.natoms_ = self.__natoms()
|
|
128
|
+
self.nframes_ = self.__len__()
|
|
129
|
+
|
|
130
|
+
def __natoms(self):
|
|
131
|
+
nat = 0
|
|
132
|
+
for fr in self:
|
|
133
|
+
nat = len(fr.positions)
|
|
134
|
+
break
|
|
135
|
+
return nat
|
|
136
|
+
|
|
137
|
+
def __iter__(self) -> Iterator[Frame]:
|
|
138
|
+
try:
|
|
139
|
+
for _ in self.trajectory:
|
|
140
|
+
yield _
|
|
141
|
+
finally:
|
|
142
|
+
# always reset pointer to header, such for and break
|
|
143
|
+
self.trajectory.reset()
|
|
144
|
+
|
|
145
|
+
def __len__(self):
|
|
146
|
+
return len([_ for _ in self.trajectory])
|
|
147
|
+
|
|
148
|
+
def __str__(self):
|
|
149
|
+
return f'Total frames: {len(self)}'
|
|
150
|
+
|
|
151
|
+
@property
|
|
152
|
+
def nframes(self):
|
|
153
|
+
""" @brief Total number of frames """
|
|
154
|
+
return self.nframes_
|
|
155
|
+
|
|
156
|
+
@property
|
|
157
|
+
def natoms(self):
|
|
158
|
+
""" @brief Number of atoms in the trajectory """
|
|
159
|
+
return self.natoms_
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
if __name__ == '__main__':
|
|
163
|
+
trj = MSTrjReader(sys.argv[1], sys.argv[2])
|
|
164
|
+
for ts in trj:
|
|
165
|
+
print(ts)
|
PyMSDump/__init__.py
ADDED
|
File without changes
|
|
Binary file
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: PyMSDump
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A parser for Materials Studio .trj format
|
|
5
|
+
Author: YujieLiu
|
|
6
|
+
Author-email:
|
|
7
|
+
Classifier: Programming Language :: Python
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: C++
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: numpy
|
|
13
|
+
|
|
14
|
+
**<font size=5> A tool to export common trajectory file from Materials Studio</font>**
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# Features
|
|
19
|
+
|
|
20
|
+
* Support full periodic boundary conditions
|
|
21
|
+
|
|
22
|
+
> Please note that this tool has converted the coordinates to match the PDB unit cell and coordinates exported by MS, so there may be differences from the original data output by Perl/Trj2Ascii, especially for the triclinic system.
|
|
23
|
+
|
|
24
|
+
* Support export move + fix atoms if exist `.pdb`
|
|
25
|
+
|
|
26
|
+
* Support export `xyz` trajectory file
|
|
27
|
+
|
|
28
|
+
* Support export `xtc` of gromacs file (includes time and step)
|
|
29
|
+
|
|
30
|
+
* Support export `.trr` format which contains velocities (`nm/ps`) and forces`(kJ/mol/nm)` if it exists
|
|
31
|
+
|
|
32
|
+
> Note that fixed atoms will have zero velocity and force, meaning their coordinates/velocity/force data won't appear in the `.trj` file.
|
|
33
|
+
|
|
34
|
+
* Support export `.txt` format (`Plain text file`) which contains all kinds of energy items and others:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
#Time(ps) Temperature(K) Potential(kJ/mol) Kinetic(KJ/mol) TotalEnergy(KJ/mol) Pressure(bar) Volume(A^3)
|
|
38
|
+
```
|
|
39
|
+
* Support Python API
|
|
40
|
+
```
|
|
41
|
+
pip install PyMSDump
|
|
42
|
+
```
|
|
43
|
+
Usage reference: [api_test](https://github.com/liuyujie714/MS_Trajdump/blob/master/PyMSDump/api_test.py)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# Usage
|
|
47
|
+
|
|
48
|
+
First locate molecular dynamics trajectory file created by `Materials Studio`, hidden file `.trj` and `.xtd` are located in same folder.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
Then download program from here: [Download](https://github.com/liuyujie714/MS_Trajdump/releases)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
* Linux
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
chmod a+x MS_dump
|
|
61
|
+
./MS_dump -s system.pdb -f system.trj
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
* Windows
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
.\MS_dump.exe -s system.pdb -f system.trj
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
Default output `MS_traj.xyz`, the comment line has box information that can be read by [Ovito](https://www.ovito.org/) software directly.
|
|
73
|
+
|
|
74
|
+
> Lattice="14.408798 0.0 0.0 0.000000 14.408798 0.0 0.000000 0.000000 14.408798" Properties=species:S:1:pos:R:3
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
**Note:**
|
|
81
|
+
|
|
82
|
+
> The exported xyz will use `C` name for all atoms if not provide pdb file, such as:
|
|
83
|
+
>
|
|
84
|
+
> ```
|
|
85
|
+
> .\MS_dump.exe -f system.trj
|
|
86
|
+
> ```
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
`-o` option can control output format
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
If you want to export `.xtc/.trr` of gromacs, use command:
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
.\MS_dump.exe -s system.pdb -f system.trj -o system.xtc
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
.\MS_dump.exe -s system.pdb -f system.trj -o system.trr
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
Also export energy items:
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
.\MS_dump.exe -f system.trj -o energy.txt
|
|
112
|
+
```
|
|
113
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
PyMSDump_.cp38-win_amd64.pyd,sha256=WYJGWPMYx6vvCIRTk6hsRcreDPJNYE-Q15S0qtwhLno,272384
|
|
2
|
+
PyMSDump/MSTrj.py,sha256=Iuw2C38W7S2rVlfBEPiEnlxBPwsbSdnvtZhQYDtZTCQ,4571
|
|
3
|
+
PyMSDump/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
pymsdump-0.1.1.dist-info/METADATA,sha256=uItE3svXqmB5e32OwNvMNqTN60cjXHTs7zPUYT5Hutg,2756
|
|
5
|
+
pymsdump-0.1.1.dist-info/WHEEL,sha256=TFndZn0SXD1XqMUEIKDojL47weLF1ldHBOPnF9B_sLo,99
|
|
6
|
+
pymsdump-0.1.1.dist-info/top_level.txt,sha256=0kBKWZ5c4yBR5LA0ZRXz4oo5CqDSVpTyPZ6jiNzuMiY,19
|
|
7
|
+
pymsdump-0.1.1.dist-info/RECORD,,
|