molforge-studio 7.4.3__py3-none-any.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.
Files changed (219) hide show
  1. main.py +71 -0
  2. molforge/__init__.py +19 -0
  3. molforge/ai/__init__.py +15 -0
  4. molforge/ai/deepseek_harness.py +185 -0
  5. molforge/ai/mcp/desktop_client.py +38 -0
  6. molforge/ai/mcp/desktop_service.py +121 -0
  7. molforge/ai/mcp/mcp_server.py +780 -0
  8. molforge/ai/mcp_bridge.py +945 -0
  9. molforge/ai/observation.py +152 -0
  10. molforge/ai/tools.py +455 -0
  11. molforge/application/__init__.py +22 -0
  12. molforge/application/ai/__init__.py +1 -0
  13. molforge/application/ai/deepseek_client.py +293 -0
  14. molforge/application/ai/observation.py +161 -0
  15. molforge/application/ai/tools.py +200 -0
  16. molforge/application/ai_proposals.py +166 -0
  17. molforge/application/bio_selection.py +143 -0
  18. molforge/application/builtin_commands.py +1445 -0
  19. molforge/application/calculators/__init__.py +10 -0
  20. molforge/application/calculators/base.py +143 -0
  21. molforge/application/calculators/calchem_engine.py +67 -0
  22. molforge/application/calculators/calchem_subprocess_worker.py +109 -0
  23. molforge/application/calculators/gaussian_engine.py +59 -0
  24. molforge/application/calculators/gaussian_job_spec.py +240 -0
  25. molforge/application/calculators/orca_engine.py +92 -0
  26. molforge/application/calculators/qc_input_generator.py +300 -0
  27. molforge/application/calculators/registry.py +29 -0
  28. molforge/application/calculators/rest_engine.py +262 -0
  29. molforge/application/command_bus.py +139 -0
  30. molforge/application/commands.py +55 -0
  31. molforge/application/conformers.py +143 -0
  32. molforge/application/document_session.py +156 -0
  33. molforge/application/events.py +74 -0
  34. molforge/application/fragment_catalog.py +422 -0
  35. molforge/application/fragment_commands.py +268 -0
  36. molforge/application/geometry_commands.py +84 -0
  37. molforge/application/history.py +105 -0
  38. molforge/application/internal_coordinates.py +293 -0
  39. molforge/application/invalidation.py +1174 -0
  40. molforge/application/jobs.py +185 -0
  41. molforge/application/measurement.py +167 -0
  42. molforge/application/measurement_targets.py +264 -0
  43. molforge/application/modeling_commands.py +61 -0
  44. molforge/application/plugins.py +197 -0
  45. molforge/application/ports/editor2d.py +85 -0
  46. molforge/application/reaction.py +75 -0
  47. molforge/application/selection.py +164 -0
  48. molforge/application/selection_commands.py +31 -0
  49. molforge/application/trajectory.py +120 -0
  50. molforge/application/trajectory_analysis.py +231 -0
  51. molforge/application/workspace_registry.py +226 -0
  52. molforge/core/__init__.py +12 -0
  53. molforge/core/conformer.py +45 -0
  54. molforge/core/molecule.py +150 -0
  55. molforge/core/orbital.py +33 -0
  56. molforge/core/properties.py +43 -0
  57. molforge/domain/__init__.py +12 -0
  58. molforge/domain/biomolecule.py +99 -0
  59. molforge/domain/chemical_summary.py +129 -0
  60. molforge/domain/chemistry.py +13 -0
  61. molforge/domain/coordinate_store.py +164 -0
  62. molforge/domain/coordination.py +133 -0
  63. molforge/domain/custom_fragments.py +255 -0
  64. molforge/domain/document.py +469 -0
  65. molforge/domain/element_reference.json +598 -0
  66. molforge/domain/elements.py +188 -0
  67. molforge/domain/ids.py +58 -0
  68. molforge/domain/massive_system.py +246 -0
  69. molforge/domain/periodic.py +116 -0
  70. molforge/domain/provenance.py +115 -0
  71. molforge/domain/topology.py +364 -0
  72. molforge/infrastructure/__init__.py +23 -0
  73. molforge/infrastructure/hpc/cluster_config.py +122 -0
  74. molforge/infrastructure/hpc/remote_executor.py +212 -0
  75. molforge/infrastructure/hpc/slurm_generator.py +93 -0
  76. molforge/io/__init__.py +35 -0
  77. molforge/io/calchem_bridge.py +407 -0
  78. molforge/io/calculators.py +893 -0
  79. molforge/io/cclib_adapter.py +422 -0
  80. molforge/io/conformers.py +183 -0
  81. molforge/io/cube_reader.py +215 -0
  82. molforge/io/custom_fragments.py +79 -0
  83. molforge/io/format_matrix.py +157 -0
  84. molforge/io/gemmi_adapter.py +150 -0
  85. molforge/io/history_skill.py +46 -0
  86. molforge/io/mdanalysis_adapter.py +155 -0
  87. molforge/io/mforge_storage.py +261 -0
  88. molforge/io/multiwfn_driver.py +614 -0
  89. molforge/io/openbabel_adapter.py +265 -0
  90. molforge/io/openbabel_handler.py +33 -0
  91. molforge/io/rdkit_adapter.py +1865 -0
  92. molforge/io/readers/__init__.py +10 -0
  93. molforge/io/readers/cube_reader.py +71 -0
  94. molforge/io/readers/gjf_reader.py +110 -0
  95. molforge/io/readers/glog_reader.py +45 -0
  96. molforge/io/readers/mol2_reader.py +36 -0
  97. molforge/io/readers/mol_reader.py +56 -0
  98. molforge/io/readers/pdb_reader.py +39 -0
  99. molforge/io/readers/smi_reader.py +40 -0
  100. molforge/io/readers/xyz_reader.py +47 -0
  101. molforge/io/registry.py +128 -0
  102. molforge/io/writers/__init__.py +7 -0
  103. molforge/io/writers/gjf_writer.py +68 -0
  104. molforge/io/writers/pdb_writer.py +37 -0
  105. molforge/io/writers/png_writer.py +31 -0
  106. molforge/io/writers/svg_writer.py +111 -0
  107. molforge/io/writers/xyz_writer.py +39 -0
  108. molforge/rendering/__init__.py +21 -0
  109. molforge/rendering/benchmark.py +121 -0
  110. molforge/rendering/bridge.py +60 -0
  111. molforge/rendering/contracts.py +119 -0
  112. molforge/rendering/glyph_scene.py +279 -0
  113. molforge/rendering/ketcher_bridge.py +131 -0
  114. molforge/rendering/ketcher_id_mapping.py +110 -0
  115. molforge/rendering/materials.py +127 -0
  116. molforge/rendering/molstar_backend.py +245 -0
  117. molforge/rendering/native_labels.py +134 -0
  118. molforge/rendering/orbitals.py +139 -0
  119. molforge/rendering/vtk_backend.py +2294 -0
  120. molforge/runtime.py +29 -0
  121. molforge/server/__init__.py +1 -0
  122. molforge/server/api_bridge.py +947 -0
  123. molforge/ui/__init__.py +1 -0
  124. molforge/ui/assets/caffeine_2d.svg +150 -0
  125. molforge/ui/assets/caffeine_3d_preview.svg +209 -0
  126. molforge/ui/assets/caffeine_preview.json +302 -0
  127. molforge/ui/assets/icons/atom.svg +1 -0
  128. molforge/ui/assets/icons/bond.svg +1 -0
  129. molforge/ui/assets/icons/cleanup.svg +1 -0
  130. molforge/ui/assets/icons/export.svg +1 -0
  131. molforge/ui/assets/icons/fragments.svg +1 -0
  132. molforge/ui/assets/icons/history.svg +1 -0
  133. molforge/ui/assets/icons/jobs.svg +1 -0
  134. molforge/ui/assets/icons/measure.svg +1 -0
  135. molforge/ui/assets/icons/molecules.svg +1 -0
  136. molforge/ui/assets/icons/overview.svg +1 -0
  137. molforge/ui/assets/icons/ring.svg +1 -0
  138. molforge/ui/assets/icons/search.svg +1 -0
  139. molforge/ui/assets/icons/select.svg +1 -0
  140. molforge/ui/assets/icons/settings.svg +1 -0
  141. molforge/ui/assets/icons/templates.svg +1 -0
  142. molforge/ui/assets/molforge_logo.ico +0 -0
  143. molforge/ui/assets/molforge_logo.png +0 -0
  144. molforge/ui/atom_labels.py +92 -0
  145. molforge/ui/bio_structure_dialog.py +57 -0
  146. molforge/ui/conformer_dialog.py +151 -0
  147. molforge/ui/dialogs/__init__.py +2 -0
  148. molforge/ui/dialogs/aim_qtaim_dialog.py +533 -0
  149. molforge/ui/dialogs/calchem_orbitals_dialog.py +287 -0
  150. molforge/ui/dialogs/element_fragments.py +130 -0
  151. molforge/ui/dialogs/gaussian_calculation_setup.py +308 -0
  152. molforge/ui/dialogs/hpc_job_dialog.py +427 -0
  153. molforge/ui/dialogs/vibrational_spectrum_dialog.py +381 -0
  154. molforge/ui/editor2d_widget.py +1803 -0
  155. molforge/ui/element_picker.py +218 -0
  156. molforge/ui/gmv_window_manager.py +65 -0
  157. molforge/ui/gromacs_job_dialog.py +47 -0
  158. molforge/ui/hotkeys.py +107 -0
  159. molforge/ui/i18n.py +237 -0
  160. molforge/ui/live_llm_dialog.py +135 -0
  161. molforge/ui/llm_config_dialog.py +103 -0
  162. molforge/ui/modeling_actions.py +176 -0
  163. molforge/ui/molstar_widget.py +98 -0
  164. molforge/ui/molstar_window.py +85 -0
  165. molforge/ui/panels.py +2966 -0
  166. molforge/ui/qc_result_dialog.py +1924 -0
  167. molforge/ui/render3d_widget.py +1579 -0
  168. molforge/ui/scrolling.py +52 -0
  169. molforge/ui/settings_panel.py +330 -0
  170. molforge/ui/shells/__init__.py +4 -0
  171. molforge/ui/shells/base_shell.py +72 -0
  172. molforge/ui/shells/document_tabs.py +715 -0
  173. molforge/ui/shells/studio_2d.py +339 -0
  174. molforge/ui/shells/studio_3d.py +401 -0
  175. molforge/ui/shells/studio_split.py +370 -0
  176. molforge/ui/shells/workflow_inputs.py +698 -0
  177. molforge/ui/theme.py +719 -0
  178. molforge/ui/trajectory_window.py +333 -0
  179. molforge/ui/views.py +892 -0
  180. molforge/ui/vtk_multiview_widget.py +141 -0
  181. molforge/ui/welcome_window.py +223 -0
  182. molforge/ui/window.py +3320 -0
  183. molforge/workflows/__init__.py +25 -0
  184. molforge/workflows/assets/OSC_MD_workflows/templates/01-MD/delete_solvent.py +216 -0
  185. molforge/workflows/assets/OSC_MD_workflows/templates/02-RDF/extract_atoms.py +60 -0
  186. molforge/workflows/assets/OSC_MD_workflows/templates/02-RDF/extract_atoms_example.py +22 -0
  187. molforge/workflows/assets/OSC_MD_workflows/templates/03-/342/225/244/320/225/342/225/250/342/226/221/342/225/250/320/246/342/225/244/320/227/342/225/250/342/225/226/342/225/250/342/224/220/342/225/244/320/225/342/225/250/320/247/342/225/250/342/226/221/342/225/244/320/224/321/202/320/245/320/254/342/225/250/320/265/analysis_mol.py +244 -0
  188. molforge/workflows/assets/OSC_MD_workflows/templates/04-/342/225/244/320/224/321/202/320/245/320/241/342/225/250/320/254/342/225/244/320/227/321/202/320/245/320/247/321/202/320/244/320/264/342/225/244/320/225/342/225/250/342/224/220/342/225/250/320/246/342/225/244/320/225/321/202/320/245/320/241/342/225/250/342/225/242/rms_roughness.py +33 -0
  189. molforge/workflows/assets/OSC_MD_workflows/templates/04-/342/225/244/320/224/321/202/320/245/320/241/342/225/250/320/254/342/225/244/320/227/321/202/320/245/320/247/321/202/320/244/320/264/342/225/244/320/225/342/225/250/342/224/220/342/225/250/320/246/342/225/244/320/225/321/202/320/245/320/241/342/225/250/342/225/242/xpm_2.py +117 -0
  190. molforge/workflows/assets/OSC_MD_workflows/templates/09-/342/225/244/320/231/342/225/250/320/240/342/225/250/320/277/342/225/244/320/227/342/225/250/320/256/342/225/250/320/247/marcus_rate.py +60 -0
  191. molforge/workflows/assets/esp-surface-analysis/scripts/compute_descriptors.py +134 -0
  192. molforge/workflows/assets/esp-surface-analysis/scripts/parse_surfanalysis.py +58 -0
  193. molforge/workflows/assets/esp-surface-analysis/scripts/plot_esp_hist.py +115 -0
  194. molforge/workflows/assets/homo-lumo-plot/extract_orb_energy.py +57 -0
  195. molforge/workflows/assets/homo-lumo-plot/make_level_plot.py +76 -0
  196. molforge/workflows/assets/homo-lumo-plot/run_pipeline.py +84 -0
  197. molforge/workflows/assets/osc-energy-level-diagram/scripts/extract_levels.py +60 -0
  198. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_editable_pptx.py +122 -0
  199. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_energy_table.py +66 -0
  200. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_level_lines_diagram.py +148 -0
  201. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_rectangle_diagram.py +148 -0
  202. molforge/workflows/assets/osc-energy-level-diagram/scripts/verify_from_log.py +45 -0
  203. molforge/workflows/dipole_analysis.py +32 -0
  204. molforge/workflows/esp_surface.py +36 -0
  205. molforge/workflows/gromacs_submit.py +167 -0
  206. molforge/workflows/homo_lumo_plot.py +59 -0
  207. molforge/workflows/igmh_interaction.py +111 -0
  208. molforge/workflows/md_rdf_analysis.py +134 -0
  209. molforge/workflows/md_studio.py +255 -0
  210. molforge/workflows/osc_energy_diagram.py +24 -0
  211. molforge/workflows/planarity_analysis.py +66 -0
  212. molforge/workflows/reorganization_energy.py +166 -0
  213. molforge/workflows/scientific_workflows.py +650 -0
  214. molforge_studio-7.4.3.dist-info/METADATA +215 -0
  215. molforge_studio-7.4.3.dist-info/RECORD +219 -0
  216. molforge_studio-7.4.3.dist-info/WHEEL +5 -0
  217. molforge_studio-7.4.3.dist-info/entry_points.txt +3 -0
  218. molforge_studio-7.4.3.dist-info/licenses/LICENSE +93 -0
  219. molforge_studio-7.4.3.dist-info/top_level.txt +2 -0
@@ -0,0 +1,25 @@
1
+ from __future__ import annotations
2
+ import importlib.util as _ilu
3
+ import sys as _sys
4
+ from pathlib import Path as _Path
5
+
6
+ _PKG_DIR = _Path(__file__).resolve().parent
7
+ for _mod_name in (
8
+ "esp_surface",
9
+ "homo_lumo_plot",
10
+ "osc_energy_diagram",
11
+ "reorganization_energy",
12
+ "dipole_analysis",
13
+ "planarity_analysis",
14
+ "md_rdf_analysis",
15
+ "igmh_interaction",
16
+ ):
17
+ _full = f"{__name__}.{_mod_name}"
18
+ _fp = _PKG_DIR / f"{_mod_name}.py"
19
+ if _full not in _sys.modules and _fp.is_file():
20
+ _spec = _ilu.spec_from_file_location(_full, str(_fp))
21
+ if _spec and _spec.loader:
22
+ _mod = _ilu.module_from_spec(_spec)
23
+ _sys.modules[_full] = _mod
24
+ _spec.loader.exec_module(_mod)
25
+ globals()[_mod_name] = _mod
@@ -0,0 +1,216 @@
1
+ """
2
+ Author: Jiahao Xie
3
+ Phd in JLU
4
+
5
+ This code is a part of the Jilin Artificial-intelligence aided Materials-design Integrated Package (JAMIP) Software.
6
+ If you use the results generated by this code in your publication, be sure to cite:
7
+ Zhao X G, Zhou K, Xing B, et al.
8
+ JAMIP: an artificial-intelligence aided data-driven infrastructure for computational materials informatics[J].
9
+ Science Bulletin, 2021, 66(19): 1973-1985.
10
+ """
11
+ import random
12
+
13
+ def change_atom_part(line:str, new_index:int):
14
+ atom_part = line[:11]
15
+ new_atom_part = atom_part.replace(atom_part[6:], '{:>5}'.format(new_index))
16
+ return line.replace(atom_part, new_atom_part)
17
+
18
+ def change_atom_part2(line:str, new_index:int):
19
+ atom_part = line[13:20]
20
+ new_atom_part = atom_part.replace(atom_part[2:], '{:>5}'.format(new_index))
21
+ return line.replace(atom_part, new_atom_part)
22
+
23
+ def change_mol_part(line:str, new_index:int):
24
+ mol_part = line[17:26]
25
+ new_mol_part = mol_part.replace(mol_part[5:9], '{:>4}'.format(new_index))
26
+ return line.replace(mol_part, new_mol_part)
27
+
28
+ def change_mol_part2(line:str, new_index:int):
29
+ mol_part = line[:9]
30
+ new_mol_part = mol_part.replace(mol_part[:5], '{:>5}'.format(new_index))
31
+ return line.replace(mol_part, new_mol_part)
32
+
33
+ def main(structure_file_name:str, new_structure_file_name:str,
34
+ solvent_mol_name:str, delet_mol_num:int):
35
+ # read origin file
36
+ origin_file = open(structure_file_name)
37
+ filelines = origin_file.readlines()
38
+ origin_file.close()
39
+
40
+ # read&get atom, mol, line indices
41
+ solvent_atom_indices = []
42
+ solvent_atom_mol_indices = []
43
+ solvent_atom_line_indices = []
44
+ for i, line in enumerate(filelines):
45
+ if solvent_mol_name in line:
46
+ solvent_atom_indices.append(int(line.split()[1]))
47
+ solvent_atom_mol_indices.append(int(line[22:26]))
48
+ solvent_atom_line_indices.append(i)
49
+ solvent_atom_num = len(solvent_atom_indices)
50
+ solvent_mol_num = solvent_atom_mol_indices[-1]
51
+
52
+ # check
53
+ #print(solvent_atom_num, solvent_mol_num, solvent_atom_num%solvent_mol_num)
54
+ assert solvent_atom_num%solvent_mol_num == 0, \
55
+ 'Non-consistent solvent molecule atom number!'
56
+
57
+ # calc delete/left mol indices
58
+ all_mol_indices = [i for i in range(1, solvent_mol_num+1)]
59
+ delet_mol_indices = random.sample(all_mol_indices, delet_mol_num)
60
+ delet_mol_indices.sort()
61
+ print('deleted mol indices:', delet_mol_indices)
62
+ left_mol_origin_indices = list(set(all_mol_indices)-set(delet_mol_indices))
63
+ left_mol_origin_indices.sort()
64
+
65
+ # calc left lines' indices
66
+ delet_lines_indices = []
67
+ for i, mol_index in enumerate(solvent_atom_mol_indices):
68
+ if mol_index in delet_mol_indices:
69
+ delet_lines_indices.append(solvent_atom_line_indices[i])
70
+ #print(delet_lines_indices)
71
+ left_lines_indices = list(set([x for x in range(len(filelines))])-set(delet_lines_indices))
72
+ left_lines_indices.sort()
73
+ # print(delet_lines_indices)
74
+
75
+ # change nol&atom indices
76
+ new_file_lines = filelines.copy()
77
+ new_atom_index = solvent_atom_indices[0]
78
+ for i, line in enumerate(filelines):
79
+ if solvent_mol_name in line:
80
+ mol_index = int(line[22:26])
81
+ if mol_index in delet_mol_indices: continue
82
+ new_atom_index += 1
83
+ new_mol_index = left_mol_origin_indices.index(mol_index)+1
84
+ new_file_line = change_mol_part(line, new_mol_index)
85
+ new_file_lines[i] = change_atom_part(new_file_line, new_atom_index)
86
+
87
+ # calc left lines' indices
88
+ delet_lines_indices = []
89
+ for i, mol_index in enumerate(solvent_atom_mol_indices):
90
+ if mol_index in delet_mol_indices:
91
+ delet_lines_indices.append(solvent_atom_line_indices[i])
92
+ #print(delet_lines_indices)
93
+ left_lines_indices = list(set([x for x in range(len(filelines))])-set(delet_lines_indices))
94
+ left_lines_indices.sort()
95
+
96
+ # generate new file contents
97
+ new_file_lines = [new_file_lines[i] for i in left_lines_indices]
98
+
99
+ # write new file
100
+ new_file = open(new_structure_file_name, 'w')
101
+ new_file.writelines(new_file_lines)
102
+ new_file.close()
103
+
104
+
105
+ def main_gro(structure_file_name:str, new_structure_file_name:str,
106
+ solvent_mol_name:str, delet_mol_num:int):
107
+ import re
108
+ pattern = re.compile(r'[0-9]+{}'.format(solvent_mol_name))
109
+ #str = u''
110
+ #print(pattern.search(str))
111
+ # read origin file
112
+ if '.gro' in structure_file_name:
113
+ file_type = 'gro'
114
+ elif '.pdb' in structure_file_name:
115
+ file_type = 'pdb'
116
+ else: raise('Input structure file name error')
117
+ origin_file = open(structure_file_name)
118
+ filelines = origin_file.readlines()
119
+ origin_file.close()
120
+
121
+ # read&get atom, mol, line indices
122
+ solvent_atom_indices = []
123
+ solvent_atom_mol_indices = []
124
+ solvent_atom_line_indices = []
125
+ solvent_atom_num=0
126
+ for i, line in enumerate(filelines):
127
+ if pattern.search(line):
128
+ solvent_atom_num+=1
129
+ solvent_atom_indices.append(int(line[15:20]))
130
+ #solvent_atom_indices.append(int(line.split()[1]))
131
+ solvent_atom_mol_indices.append(int(line[:5]))
132
+ solvent_atom_line_indices.append(i)
133
+ solvent_atom_num = len(solvent_atom_indices)
134
+ solvent_mol_num = len(solvent_atom_mol_indices)
135
+
136
+ # check
137
+ #print(solvent_atom_num, solvent_mol_num, solvent_atom_num%solvent_mol_num)
138
+ assert solvent_atom_num%solvent_mol_num == 0, \
139
+ 'Non-consistent solvent molecule atom number!'
140
+
141
+ # calc delete/left mol indices
142
+ all_mol_indices = [i for i in range(solvent_atom_mol_indices[0],
143
+ solvent_atom_mol_indices[-1]+1)]
144
+ delet_mol_indices = random.sample(all_mol_indices, delet_mol_num)
145
+ delet_mol_indices.sort()
146
+ print('deleted mol indices:', delet_mol_indices)
147
+ left_mol_origin_indices = list(set(all_mol_indices)-set(delet_mol_indices))
148
+ left_mol_origin_indices.sort()
149
+ #print()
150
+
151
+ # calc left lines' indices
152
+ delet_lines_indices = []
153
+ for i, mol_index in enumerate(solvent_atom_mol_indices):
154
+ if mol_index in delet_mol_indices:
155
+ delet_lines_indices.append(solvent_atom_line_indices[i])
156
+ #print(delet_lines_indices)
157
+ left_lines_indices = list(set([x for x in range(len(filelines))])-set(delet_lines_indices))
158
+ left_lines_indices.sort()
159
+ # print(delet_lines_indices)
160
+
161
+ # change nol&atom indices
162
+ new_file_lines = filelines.copy()
163
+ new_atom_index = solvent_atom_indices[0]
164
+ delta_mol_index=0
165
+ for i, line in enumerate(filelines):
166
+ if solvent_mol_name in line:
167
+ mol_index = int(line[:5])
168
+ if mol_index in left_mol_origin_indices:
169
+ new_mol_index = left_mol_origin_indices.index(mol_index)+solvent_atom_mol_indices[0]
170
+ new_file_line = change_mol_part2(line, new_mol_index)
171
+ new_file_lines[i] = change_atom_part2(new_file_line, new_atom_index)
172
+ new_atom_index += 1
173
+ if new_atom_index == 100000: new_atom_index=0
174
+ #new_file_lines[i] = change_atom_part(new_file_line, new_atom_index)
175
+ #new_file_lines[1]='{}\n'.format(new_atom_index-1)
176
+ # calc left lines' indices
177
+ delet_lines_indices = []
178
+ for i, mol_index in enumerate(solvent_atom_mol_indices):
179
+ if mol_index in delet_mol_indices:
180
+ delet_lines_indices.append(solvent_atom_line_indices[i])
181
+ #print(delet_lines_indices)
182
+ left_lines_indices = list(set([x for x in range(len(filelines))])-set(delet_lines_indices))
183
+ left_lines_indices.sort()
184
+
185
+ # generate new file contents
186
+ new_file_lines = [new_file_lines[i] for i in left_lines_indices]
187
+ new_file_lines[1]='{}\n'.format(len(new_file_lines)-3)
188
+ # write new file
189
+ new_file = open(new_structure_file_name, 'w')
190
+ new_file.writelines(new_file_lines)
191
+ new_file.close()
192
+
193
+
194
+ def change_complex_top(delet_mol_num, line_num):
195
+ iline=line_num-1
196
+ with open('complex.top','r') as file:
197
+ data = file.readlines()
198
+ keyline = data[iline].strip().split()
199
+ origin_num = int(keyline[-1])
200
+ new_num = origin_num-delet_mol_num
201
+ data[iline]=keyline[0]+' {} \n'.format(new_num)
202
+ with open('complex.top','w') as file:
203
+ file.writelines(data)
204
+
205
+
206
+ if __name__ == '__main__':
207
+ # input infos
208
+ structure_file_name = 'npt_input.gro'
209
+ new_structure_file_name = 'npt.gro'
210
+ solvent_mol_name = 'CF'
211
+ delet_mol_num = 200
212
+
213
+ main_gro(structure_file_name, new_structure_file_name,
214
+ solvent_mol_name, delet_mol_num)
215
+ change_complex_top(delet_mol_num, line_num=55)
216
+
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ extract_atoms.py —— 从 GROMACS .gro 中按原子名提取指定分子的原子序号(RDF 组定义)
5
+
6
+ 模板来源:Ternary_Datas/RDF/backbone-md1/test-MD1/A11.py
7
+ 泛化说明:
8
+ 1) 把目标原子的"原子名列表"填进 ATOM_NAMES;
9
+ 2) 把 .gro 中"功能分子前的行数 + 标题行"作为跳过行(默认 2);
10
+ 3) 每个分子原子数写入 ATOMS_PER_MOL(用于每 N 个原子换行,方便核对/生成 ndx)。
11
+
12
+ 用法:
13
+ python extract_atoms.py 1.gro > atoms.out
14
+ # atoms.out 即 gmx rdf -n index.ndx 中该组的原子号,或直接喂给 make_ndx/-sel
15
+ """
16
+ import sys
17
+
18
+ # ============ 需要按体系修改的配置 ============
19
+ GRO_FILE = sys.argv[1] if len(sys.argv) > 1 else '1.gro'
20
+ OUT_FILE = 'atoms.out'
21
+ SKIP_LINES = 2 # 跳过标题行与原子计数行
22
+ TARGET_RESNAME = 'HDO' # 仅匹配该残基名(或置 None 忽略)
23
+ ATOMS_PER_MOL = 68 # 每个目标分子的原子数(换行用,可设 1e9 不换行)
24
+
25
+ # 目标原子名列表(示例为 HDO 骨架,来自 A11.py;新体系替换为你的分子原子名)
26
+ ATOM_NAMES = [
27
+ 'C14','C15','C16','C17','C18','C19','C20','C21','C22','C23','C24','O1',
28
+ 'C25','N5','C26','N6','C40','C41','C42','C43','C44','C45','C46','C47',
29
+ 'C48','C49','O2','C50','C51','N7','C52','N8','Cl1','Cl2','Cl3','Cl4',
30
+ 'C1','C2','C3','C4','C5','C6','N1','N2','S1','C7','C8','N3','N4','C9',
31
+ 'S2','C10','C11','S3','C12','C13','S4','C31','C32','C33','S5','C34','C35',
32
+ ]
33
+ # =============================================
34
+
35
+ name_set = set(ATOM_NAMES)
36
+
37
+ def main():
38
+ out = open(OUT_FILE, 'w')
39
+ count = 0
40
+ with open(GRO_FILE) as f:
41
+ for i, line in enumerate(f):
42
+ if i < SKIP_LINES:
43
+ continue
44
+ fields = line.split()
45
+ if len(fields) < 5:
46
+ continue
47
+ resname = fields[0][-5:] if len(fields[0]) >= 5 else fields[0]
48
+ atomname = fields[1]
49
+ atomnum = fields[2]
50
+ if TARGET_RESNAME and TARGET_RESNAME not in fields[0]:
51
+ continue
52
+ if atomname in name_set:
53
+ count += 1
54
+ sep = '\n' if count % ATOMS_PER_MOL == 0 else ' '
55
+ out.write(f'{atomnum}{sep}')
56
+ out.close()
57
+ print(f'[info] 提取原子数: {count}', file=sys.stderr)
58
+
59
+ if __name__ == '__main__':
60
+ main()
@@ -0,0 +1,22 @@
1
+ filename = open('1.gro')
2
+ filename2 = open('A11.out','w')
3
+ num = 1
4
+ num2 = 1
5
+ HDO = ['C14','C15','C16','C17','C18','C19','C20','C21','C22','C23','C24','O1','C25','N5','C26','N6','C40','C41','C42','C43','C44','C45','C46','C47','C48','C49','O2','C50','C51','N7','C52','N8','Cl1','Cl2','Cl3','Cl4','C1','C2','C3','C4','C5','C6','N1','N2','S1','C7','C8','N3','N4','C9','S2','C10','C11','S3 ','C12','C13','S4 ','C31','C32','C33','S5 ','C34','C35','O3','O4',]
6
+ for line in filename.readlines():
7
+ if num > 2:
8
+ lineArr = line.strip().split()
9
+ num+=1
10
+ if num > 38811:
11
+ break
12
+ if lineArr[1] in HDO:
13
+ if num2 % 15 ==0:
14
+ filename2.write(lineArr[2]+'\n')
15
+ num2 += 1
16
+ else:
17
+ filename2.write(lineArr[2]+' ')
18
+ num2 += 1
19
+
20
+ else:
21
+ num+=1
22
+
@@ -0,0 +1,244 @@
1
+ #import random
2
+ import numpy as np
3
+ import pandas as pd
4
+ from scipy.optimize import leastsq
5
+ #import matplotlib.pyplot as plt
6
+ #from mpl_toolkits.mplot3d import Axes3D
7
+ from sklearn.metrics import mean_squared_error
8
+ from sklearn.linear_model import LinearRegression
9
+
10
+
11
+ def fit_plane(points_xyzs):
12
+
13
+ vecs = [reg(points_xyzs),
14
+ estimate_plane_with_leastsq(points_xyzs),
15
+ plane_normal_vector_svd(points_xyzs)]
16
+ errors = [evaluate(points_xyzs,vec) for vec in vecs]
17
+ #print(errors)
18
+ errors = np.array(errors)
19
+ return vecs[np.argmin(errors[:,0])],errors[np.argmin(errors[:,0])]
20
+ #print(vecs)
21
+ #return vecs
22
+
23
+ def evaluate(points, normal_vector):
24
+ pts = np.array(points)
25
+ mean_pt = np.mean(pts,axis=0)
26
+ distances = np.abs(np.dot(points-mean_pt,normal_vector) / np.linalg.norm(normal_vector))
27
+ # 计算平均距离
28
+ mean_distance = np.mean(distances)
29
+ # 计算标准差
30
+ std_distance = np.std(distances)
31
+ return mean_distance, std_distance
32
+
33
+ def reg(pts):
34
+ X = np.array(pts)
35
+ reg = LinearRegression().fit(X[:, :2], X[:, 2].reshape(-1, 1))
36
+ normal_vector = np.append(reg.coef_, -1)
37
+ normal_vector = normal_vector / np.linalg.norm(normal_vector)
38
+ y_pred = reg.predict(X[:, :2])
39
+ #mse = mean_squared_error(X[:, 2].reshape(-1, 1), y_pred)
40
+ #print(mse)
41
+ return normal_vector
42
+
43
+ def plane_normal_vector_svd(points):
44
+ points = np.asarray(points)
45
+ mean = np.mean(points, axis=0)
46
+ centered_points = points - mean
47
+ _, _, vh = np.linalg.svd(centered_points, full_matrices=False)
48
+ normal_vector = vh[-1, :]
49
+ return normal_vector
50
+
51
+ #定义误差函数
52
+ def residuals(params, points, x, y, z):
53
+ a, b, c, d = params
54
+ dist = np.abs((a * x + b * y + c * z + d) / np.sqrt(a**2 + b**2 + c**2))
55
+ return dist
56
+
57
+ #对指定的点进行拟合
58
+ def estimate_plane_with_leastsq(points):
59
+ x, y, z = points[:, 0], points[:, 1], points[:, 2]
60
+ params0 = [1, 1, 1, 1]
61
+ result = leastsq(residuals, params0, args=(points, x, y, z))
62
+ a, b, c, d = result[0]
63
+ normal_vector = np.array([a, b, c]) / np.sqrt(a**2 + b**2 + c**2)
64
+ return normal_vector
65
+
66
+ def calc_mcenter(xyzs,eles):
67
+ atom_masses = {'C': 12.01, 'S': 32.06, 'H': 1.01,
68
+ 'O': 16.00, 'F': 19.00, 'N': 14.01, 'Cl': 35.45}
69
+ x_total, y_total, z_total, total_mass = 0, 0, 0, 0
70
+ for ele, (x, y, z) in zip(eles, xyzs):
71
+ elem = ''.join([c for c in ele if c.isalpha()])
72
+ mass = atom_masses[elem]
73
+ x_total += x * mass
74
+ y_total += y * mass
75
+ z_total += z * mass
76
+ total_mass += mass
77
+
78
+ x_cm = x_total / total_mass
79
+ y_cm = y_total / total_mass
80
+ z_cm = z_total / total_mass
81
+ return (x_cm,y_cm,z_cm)
82
+
83
+ def parse_data(gro_file_path:str,mols:list,fragments=None,velocity=False):
84
+ import re
85
+ import pandas as pd
86
+ origin_file = open(gro_file_path)
87
+ filelines = origin_file.readlines()
88
+ origin_file.close()
89
+
90
+ atom_line_indices=[];mol_indices=[];mol_types=[]
91
+ ele_infos=[];atom_indices=[];atom_xyzs=[];j_list=[]
92
+ patterns = [re.compile(r'[0-9]+{}'.format(mol)) for mol in mols]
93
+ for i, line in enumerate(filelines):
94
+ for j, pattern in enumerate(patterns):
95
+ if pattern.search(line):
96
+ mol=mols[j]
97
+ j_list.append(j)
98
+ break
99
+ else: continue
100
+ atom_line_indices.append(i)
101
+ mol_indices.append(int(line[:5]))
102
+ mol_types.append(mol)
103
+ ele_infos.append(line[11:15].strip())
104
+ atom_indices.append(int(line[15:20]))
105
+ #print(line.split()[0:2])
106
+ if velocity:
107
+ atom_xyzs.append([float(num) for num in line.split()[-6:-3]])
108
+ continue
109
+ atom_xyzs.append([float(num) for num in line.split()[-3:]])
110
+
111
+ atom_line_indices=np.array(atom_line_indices);mol_indices=np.array(mol_indices);mol_types=np.array(mol_types)
112
+ ele_infos=np.array(ele_infos);atom_indices=np.array(atom_indices);atom_xyzs=np.array(atom_xyzs)
113
+
114
+ #mols_dict={}
115
+ unique_mol_indices = np.unique(mol_indices)
116
+ indices_list=[]
117
+ mol_type_list=[]
118
+ ele_infos_list=[]
119
+ mol_fragments_indices_list = []
120
+ mol_fragments_eles_list = []
121
+ mol_fragments_xyzs_list = []
122
+ mol_fragments_vecs_list = []
123
+ mol_fragments_vecs_err_list = []
124
+ mol_fragments_mcenters_list = []
125
+ for i, mol_index in enumerate(unique_mol_indices):
126
+ indices = np.where(mol_indices==mol_index)[0]
127
+ indices_list.append(indices)
128
+ mol_type = mol_types[indices[0]]
129
+ mol_type_list.append(mol_type)
130
+ eles = ele_infos[indices]
131
+ ele_infos_list.append(eles)
132
+ if fragments:
133
+ mol_fragments_eles = fragments[j_list[indices[0]]]
134
+ mol_fragments_eles_list.append(mol_fragments_eles)
135
+ mol_fragments_indices = [[j for j, item in enumerate(eles)
136
+ if item in mol_fragment_ele]
137
+ for mol_fragment_ele in mol_fragments_eles]
138
+ mol_fragments_indices_list.append(mol_fragments_indices)
139
+ mol_fragments_xyzs = [atom_xyzs[indices][mol_fragment_indices]
140
+ for mol_fragment_indices in mol_fragments_indices]
141
+ mol_fragments_xyzs_list.append(mol_fragments_xyzs)
142
+ mcenters = [calc_mcenter(xyzs, eles) for xyzs, eles in zip(
143
+ mol_fragments_xyzs,mol_fragments_eles)]
144
+ mol_fragments_mcenters_list.append(mcenters)
145
+ vecs_errs_list = [fit_plane(pts) for pts in mol_fragments_xyzs]
146
+ mol_fragments_vecs_list.append([vec_err[0] for vec_err in vecs_errs_list])
147
+ mol_fragments_vecs_err_list.append([vec_err[1] for vec_err in vecs_errs_list])
148
+
149
+
150
+ datasheet = pd.DataFrame({'mol_index':unique_mol_indices,
151
+ 'line_indices':indices_list,
152
+ 'xyzs':[atom_xyzs[indices] for indices in indices_list],
153
+ 'elements':ele_infos_list,#[ele_infos[indices] for indices in indices_list],
154
+ 'atom_indices':[atom_indices[indices] for indices in indices_list],
155
+ 'mol_type':mol_type_list,#[mol_types[indices[0]] for indices in indices_list],
156
+ 'vec':[fit_plane(pts) for pts in [atom_xyzs[indices] for indices in indices_list]],
157
+ 'geo_center':[np.mean(atom_xyzs[indices],axis=0) for indices in indices_list]}
158
+ )
159
+ if fragments:
160
+ datasheet['fragments_inerindices'] = mol_fragments_indices_list
161
+ datasheet['fragments_vecs'] = mol_fragments_vecs_list
162
+ datasheet['fragments_vecs_err'] =mol_fragments_vecs_err_list
163
+ datasheet['fragments_xyzs'] = mol_fragments_xyzs_list
164
+ datasheet['fragments_mcenters'] =mol_fragments_mcenters_list
165
+ return datasheet
166
+
167
+ def calc_angle(v1,v2):
168
+ v1 = np.array(v1); v2 = np.array(v2)
169
+ dot = np.dot(v1,v2)
170
+ v1_norm = np.linalg.norm(v1); v2_norm = np.linalg.norm(v2)
171
+ cos_angle = dot/(v1_norm*v2_norm)
172
+ angle = np.arccos(cos_angle)
173
+ return np.degrees(angle)
174
+
175
+ def read_md_cut(structure_file_name):
176
+ import itertools
177
+ #structure_file_name = 'md_cut.gro'
178
+ PM6A = [['C1','C2','C3','C4','C5','C6','C7','C8','C9','C10','S1','S2','C28','C29','S7','C30','C31','C32','C33','S8','C34','C35'],
179
+ ['C69','C70','S9','C71','C72','C73','C74','C75','C76','C77','C78','S10','C79','S11','C80','C81','S12','C82','C83','C84','C85'],
180
+ ['C137','C138','S17','C139','C140','C141','C142','C143','C144','C145','C146','S18','C147','S19','C148','C149','S20','C150','C151','C152','C153','C154'],
181
+ ['C205','C206','S25','C207','C208','C209','C210','C211','C212','C213','C214','S26','C215','S27','C216','C217','S28','C218','C219','C220','C221','C222'],
182
+ ['C11','C12','C13','C14','C15','C16','C17','C18','C19','C20','C21','C22','C23','O1','O2','C24','C25','S6','C26','S3','S4','S5','C27','C38'],
183
+ ['C87','C90','S13','C93','C94','C99','C104','S14','C107','C108','C109','C112','O3','C113','C114','C115','C116','O4','C117','S15','C118','S16','C120','C121'],
184
+ ['C155','C158','S21','C161','C162','C167','C172','S22','C175','C176','C177','C180','O5','C181','C182','C183','C184','O6','C185','S23','C186','S24','C188','C189'],
185
+ ['C239','C240','S29','C241','C242','C243','C244','S30','C245','C246','C247','C248','O7','C249','C250','C251','C252','O8','C253','S31','C254','S32','C256','C257']]
186
+ HDOA = [['C1','C2','C3','C4','C5','C6','N1','N2','S1','C7','C8','N3','N4','C9','S2','C10','C11','S3','C12','C13','S4','C31','C32','C33','S5','C34','C35','O3','O4'],
187
+ ['C40','C41','H17','C42','C43','C44','C45','C46','C47','C48','H18','C49','O2','C50','C51','N7','C52','N8','H89','Cl1','Cl4'],
188
+ ['C14','C15','C16','C17','C18','C19','C20','C21','C22','C23','C24','H1','O1','C25','N5','C26','N6','H16','H88','Cl2','Cl3']]
189
+ mol1='PM6';mol2='HDO'
190
+ data = parse_data(structure_file_name,mols=[mol1,mol2],fragments=[PM6A,HDOA])
191
+ #pd.options.display.max_columns = None
192
+ pd.set_option('display.max_columns', None)
193
+ pd.set_option('display.max_rows', None)
194
+ #print(data.head(3))
195
+ data.to_excel('{}_data.xlsx'.format(structure_file_name),index=False)
196
+ #print(data[data['mol_type']=='DT'].index.values)
197
+ #DT1=data[data['mol_type']=='PM6'].index.values[0]
198
+ #plot_mol_vec_pic(data.loc[data['mol_type']=='PM6'].iloc[0])
199
+ #plot_mol_fragments_vec_pic(data.loc[data['mol_type']=='HDO'].iloc[-2])
200
+ M1data = data.loc[data['mol_type']==mol1]
201
+ M2data = data.loc[data['mol_type']==mol2]
202
+ #print(M2data.head(3))
203
+ #print(M1data.head(3))
204
+ #M1l = list(range(len(M1data))); M2l = list(range(len(M2data)))
205
+ Mol_combs = list(itertools.product(M1data.index.tolist(),
206
+ M2data.index.tolist()))
207
+ Frag_combs = list(itertools.product(list(range(len(PM6A))),
208
+ list(range(len(HDOA)))))
209
+
210
+ M1list=[];M2list=[];M1F=[];M2F=[];disl=[];an=[]
211
+ for Mol_comb in Mol_combs:
212
+ for Frag_comb in Frag_combs:
213
+ M1list.append(Mol_comb[0]+1);M1F.append(Frag_comb[0]+1)
214
+ M2list.append(Mol_comb[1]+1);M2F.append(Frag_comb[1]+1)
215
+ #print(Mol_comb,Frag_comb)
216
+ mcenter1 = np.array(
217
+ M1data.loc[Mol_comb[0],'fragments_mcenters'][Frag_comb[0]])
218
+ #print(Mol_comb,Frag_comb,mcenter1)
219
+ mcenter2 = np.array(
220
+ M2data.loc[Mol_comb[1],'fragments_mcenters'][Frag_comb[1]])
221
+ vec1 = M1data.loc[Mol_comb[0],'fragments_vecs'][Frag_comb[0]]
222
+ vec2 = M2data.loc[Mol_comb[1],'fragments_vecs'][Frag_comb[1]]
223
+ dis = np.linalg.norm(mcenter1-mcenter2);disl.append(dis)
224
+ angle = calc_angle(vec1, vec2);an.append(angle)
225
+ # results = results.append(pd.Series([Mol_comb,Frag_comb,dis,angle],
226
+ # index=results.columns),
227
+ # ignore_index=True)
228
+ results = pd.DataFrame(columns=['Molecule1', 'Molecule2',
229
+ 'M1Fragment','M2Fragment',
230
+ 'distance',
231
+ 'angle'],
232
+ data=np.array([M1list,M2list,M1F,M2F,disl,an]).T)
233
+ results.to_excel('{}_results.xlsx'.format(structure_file_name), sheet_name='Sheet1', index=False)
234
+ #to_csv('results.csv',index=False)
235
+
236
+ if __name__ == '__main__':
237
+ # input infos
238
+ import os
239
+ #folder = './'
240
+ for file in os.listdir():
241
+ if file.endswith('.gro'):
242
+ #structure_file_name = 'md_cut.gro'
243
+ print(file)
244
+ read_md_cut(file)
@@ -0,0 +1,33 @@
1
+ import os
2
+ import numpy as np
3
+
4
+ def read_density_map(file_path):
5
+ # 从 .dat 文件读取密度图数据
6
+ density_map = np.loadtxt(file_path)
7
+ return density_map
8
+
9
+ def calculate_rms_roughness(density_map):
10
+ # 计算均方根粗糙度
11
+ rms_roughness = np.sqrt(np.mean(np.square(density_map - np.mean(density_map))))
12
+ return rms_roughness
13
+
14
+ def process_folder(folder_path):
15
+ # 获取文件夹中所有的文件路径
16
+ file_paths = [os.path.join(folder_path, file) for file in os.listdir(folder_path) if file.endswith('.dat')]
17
+
18
+ # 循环处理每个文件
19
+ for file_path in file_paths:
20
+ # 读取密度图数据
21
+ density_map_data = read_density_map(file_path)
22
+
23
+ # 计算均方根粗糙度
24
+ rms_roughness_value = calculate_rms_roughness(density_map_data)
25
+
26
+ # 输出均方根粗糙度值
27
+ print(f'RMS Roughness for {file_path}: {rms_roughness_value}')
28
+
29
+ # 替换下面的文件夹路径为你的文件夹路径
30
+ folder_path = "D:/3/DENSI/md1"
31
+
32
+ # 处理文件夹中的所有文件
33
+ process_folder(folder_path)