MBN-tools 0.1__tar.gz
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.
- MBN_tools-0.1/MBN_tools/MBN_tools.py +119 -0
- MBN_tools-0.1/MBN_tools/__init__.py +0 -0
- MBN_tools-0.1/PKG-INFO +16 -0
- MBN_tools-0.1/setup.cfg +2 -0
- MBN_tools-0.1/setup.py +23 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'''
|
|
2
|
+
MBN Tools
|
|
3
|
+
|
|
4
|
+
A series of functions for use with the MBN Explorer software (https://mbnresearch.com/get-mbn-explorer-software).
|
|
5
|
+
|
|
6
|
+
Functions include running MBN Explorer simulations, data analysis and file manipulation.
|
|
7
|
+
'''
|
|
8
|
+
|
|
9
|
+
def run_MBN(task_file, MBN_path, show_output=False):
|
|
10
|
+
'''This function will run an MBN Explorer simulation using a specified Task file. Function returns the
|
|
11
|
+
stanard output and standard error. The show_output optional argument will print the simulation output to
|
|
12
|
+
the screen.'''
|
|
13
|
+
import subprocess
|
|
14
|
+
result = subprocess.run(MBN_path + ' -t ' + task_file, capture_output=True, text=True, creationflags=0x08000000)
|
|
15
|
+
|
|
16
|
+
if show_output:
|
|
17
|
+
print('Output:')
|
|
18
|
+
if len(result.stdout) > 0:
|
|
19
|
+
print(result.stdout)
|
|
20
|
+
else:
|
|
21
|
+
print(result.stderr)
|
|
22
|
+
|
|
23
|
+
return result.stdout, result.stderr
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def read_task_file(task_file):
|
|
27
|
+
'''This function splits a given Task file into a a dictionary of task file options and their respective
|
|
28
|
+
parameters. Useful if you want to get a specific set of task file options for use in calculations for example.'''
|
|
29
|
+
file_options = {}
|
|
30
|
+
with open(task_file) as f:
|
|
31
|
+
data = f.read().split('\n')
|
|
32
|
+
|
|
33
|
+
for i in data:
|
|
34
|
+
if '=' in i:
|
|
35
|
+
i=i.split('=')
|
|
36
|
+
try:
|
|
37
|
+
file_options[i[0].strip()] = eval(i[1].strip())
|
|
38
|
+
except (NameError, SyntaxError):
|
|
39
|
+
file_options[i[0].strip()] = i[1].strip()
|
|
40
|
+
|
|
41
|
+
return file_options
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def read_trajectory(dcd_file, frame=None):
|
|
45
|
+
''' This function uses the mdtraj module to return the coordinates of a particular DCD file.
|
|
46
|
+
A frame number can be specified. Note that this function is only compatible on unix systems
|
|
47
|
+
due to the mdtraj module.'''
|
|
48
|
+
loaded = False
|
|
49
|
+
try:
|
|
50
|
+
import mdtraj.formats as md
|
|
51
|
+
loaded = True
|
|
52
|
+
except:
|
|
53
|
+
assert loaded, 'Cannot import the mdtraj module; please run in unix'
|
|
54
|
+
|
|
55
|
+
with md.DCDTrajectoryFile(dcd_file) as f:
|
|
56
|
+
xyz, cell_lengths, cell_angles = f.read()
|
|
57
|
+
coords = (xyz)
|
|
58
|
+
|
|
59
|
+
if frame:
|
|
60
|
+
return coords[frame]
|
|
61
|
+
else:
|
|
62
|
+
return coords
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def xyz_to_pdb(xyz_file, pdb_file):
|
|
66
|
+
'''This function is meant to update coordinates of a particular system from an XYZ file
|
|
67
|
+
to a corresponding PDB file for the same system. It receives an XYZ file (xyz_file)
|
|
68
|
+
containing the new coordinates and a PDB file (pdb_file) containing old coordinates to
|
|
69
|
+
be updated, and returns a PDB file with the name of the one supplied prefixed by 'new_'.
|
|
70
|
+
It assumes one is using only the record types 'ATOM' or 'HETATM' on the PDB file, but can
|
|
71
|
+
be adjusted for other usages provided the string updated_atom is correctly modified.'''
|
|
72
|
+
with open(xyz_file) as xyz:
|
|
73
|
+
lines = xyz.readlines()
|
|
74
|
+
xyz_list = [line.strip().split() for line in lines[2:]]
|
|
75
|
+
|
|
76
|
+
with open(pdb_file) as pdb:
|
|
77
|
+
lines = pdb.readlines()
|
|
78
|
+
head = []
|
|
79
|
+
atoms = []
|
|
80
|
+
foot = []
|
|
81
|
+
atoms_done = False
|
|
82
|
+
for line in lines:
|
|
83
|
+
if line.startswith('ATOM'):
|
|
84
|
+
atoms.append(line.strip().split())
|
|
85
|
+
elif line.startswith('END'):
|
|
86
|
+
atoms_done = True
|
|
87
|
+
foot.append(line)
|
|
88
|
+
elif atoms_done:
|
|
89
|
+
foot.append(line)
|
|
90
|
+
else:
|
|
91
|
+
head.append(line)
|
|
92
|
+
|
|
93
|
+
with open('new_' + pdb_file, 'w') as new_pdb:
|
|
94
|
+
for line in head:
|
|
95
|
+
new_pdb.write(line)
|
|
96
|
+
for idx, atom in enumerate(atoms):
|
|
97
|
+
updated_atom = "{ATOM}{atom_num} {atom_name}{alt_loc_ind}{res_name} {chain_id}{res_seq_num}{res_code} {x_coord}{y_coord}{z_coord}{occ}{temp} {seg_id}{element}{charge}\n".format( #The values on the lines below can be edited to comply with other PDB types
|
|
98
|
+
ATOM=atom[0].ljust(6),
|
|
99
|
+
atom_num=atom[1].rjust(5),
|
|
100
|
+
atom_name=atom[2].ljust(4),
|
|
101
|
+
alt_loc_ind=' ',
|
|
102
|
+
res_name=atom[3].rjust(3),
|
|
103
|
+
chain_id=' ',
|
|
104
|
+
res_seq_num=atom[4].rjust(4),
|
|
105
|
+
res_code=' ',
|
|
106
|
+
x_coord=str('%3.3f' % (float(xyz_list[idx][1]))).rjust(8),
|
|
107
|
+
y_coord=str('%3.3f' % (float(xyz_list[idx][2]))).rjust(8),
|
|
108
|
+
z_coord=str('%3.3f' % (float(xyz_list[idx][3]))).rjust(8),
|
|
109
|
+
occ=str('%1.2f' % (float(atom[8]))).rjust(6),
|
|
110
|
+
temp=str('%1.2f' % (float(atom[9]))).rjust(6),
|
|
111
|
+
seg_id=atom[10].ljust(4),
|
|
112
|
+
element=atom[11].rjust(2),
|
|
113
|
+
charge=' '
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
new_pdb.write(updated_atom)
|
|
117
|
+
for line in foot:
|
|
118
|
+
new_pdb.write(line)
|
|
119
|
+
|
|
File without changes
|
MBN_tools-0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 1.1
|
|
2
|
+
Name: MBN_tools
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: Useful tools for MBN Explorer simulations and analysis
|
|
5
|
+
Home-page: https://github.com/mattdickers/MBN_tools
|
|
6
|
+
Author: Matthew Dickers
|
|
7
|
+
Author-email: mattdickers@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Download-URL: https://github.com/mattdickers/MBN_tools/archive/refs/tags/v_0.1.tar.gz
|
|
10
|
+
Description: UNKNOWN
|
|
11
|
+
Keywords: MBN Explorer,MBN Studio,Molecular Dynamics,MD,Data Analysis
|
|
12
|
+
Platform: UNKNOWN
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
MBN_tools-0.1/setup.cfg
ADDED
MBN_tools-0.1/setup.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from distutils.core import setup
|
|
2
|
+
setup(
|
|
3
|
+
name = 'MBN_tools',
|
|
4
|
+
packages = ['MBN_tools'],
|
|
5
|
+
version = '0.1',
|
|
6
|
+
license='MIT',
|
|
7
|
+
description = 'Useful tools for MBN Explorer simulations and analysis',
|
|
8
|
+
author = 'Matthew Dickers',
|
|
9
|
+
author_email = 'mattdickers@gmail.com',
|
|
10
|
+
url = 'https://github.com/mattdickers/MBN_tools',
|
|
11
|
+
download_url = 'https://github.com/mattdickers/MBN_tools/archive/refs/tags/v_0.1.tar.gz',
|
|
12
|
+
keywords = ['MBN Explorer', 'MBN Studio', 'Molecular Dynamics', 'MD', 'Data Analysis'],
|
|
13
|
+
install_requires=[
|
|
14
|
+
'numpy',
|
|
15
|
+
'mdtraj',
|
|
16
|
+
],
|
|
17
|
+
classifiers=[
|
|
18
|
+
'Development Status :: 3 - Alpha', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
|
|
19
|
+
'Intended Audience :: Science/Research',
|
|
20
|
+
'License :: OSI Approved :: MIT License',
|
|
21
|
+
'Programming Language :: Python :: 3',
|
|
22
|
+
],
|
|
23
|
+
)
|