Skip to content

Commit

Permalink
Merge pull request #23 from htz1992213/main
Browse files Browse the repository at this point in the history
Fix residence time save curve path; fix ligpargen url; fix connection not private
  • Loading branch information
htz1992213 committed Dec 19, 2023
2 parents a2245c6 + 7480aee commit 1830b92
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Change log
==========

v0.3.1
------

v0.3.0
------

v0.2.4
------

Expand Down
2 changes: 1 addition & 1 deletion mdgo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
__email__ = "tingzheng_hou@berkeley.edu"
__maintainer__ = "Tingzheng Hou"
__maintainer_email__ = "tingzheng_hou@berkeley.edu"
__version__ = "0.3.0"
__version__ = "0.3.1"
4 changes: 2 additions & 2 deletions mdgo/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"""

__author__ = "Tingzheng Hou"
__version__ = "0.3.0"
__version__ = "0.3.1"
__maintainer__ = "Tingzheng Hou"
__email__ = "tingzheng_hou@berkeley.edu"
__date__ = "Jul 19, 2021"
__date__ = "Dec 19, 2023"


from .analysis import MdRun
Expand Down
4 changes: 2 additions & 2 deletions mdgo/forcefield/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"""

__author__ = "Tingzheng Hou, Ryan Kingsbury"
__version__ = "0.3.0"
__version__ = "0.3.1"
__maintainer__ = "Tingzheng Hou, Ryan Kingsbury"
__email__ = "tingzheng_hou@berkeley.edu"
__date__ = "Jul 19, 2022"
__date__ = "Dec 19, 2023"


from .aqueous import IonLJData, Aqueous
Expand Down
15 changes: 9 additions & 6 deletions mdgo/forcefield/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(
'Chrome/88.0.4324.146 Safari/537.36"'
)
self.options.add_argument("--window-size=1920,1080")
self.options.add_argument("ignore-certificate-errors")
if headless:
self.options.add_argument("--headless")
self.options.add_experimental_option("prefs", self.preferences)
Expand All @@ -90,7 +91,7 @@ def __init__(
else:
self.web = webdriver.Chrome(service=self.server, options=self.options)
self.wait = WebDriverWait(self.web, 10)
self.web.get("http://zarbi.chem.yale.edu/ligpargen/")
self.web.get("http://traken.chem.yale.edu/ligpargen/")
time.sleep(1)
print("LigParGen server connected.")

Expand All @@ -109,9 +110,11 @@ def data_from_pdb(self, pdb_dir: str):
Args:
pdb_dir: The path to the input pdb structure file.
"""
self.web.get("http://zarbi.chem.yale.edu/ligpargen/")
self.web.get("http://traken.chem.yale.edu/ligpargen/")
upload_xpath = '//*[@id="exampleMOLFile"]'
time.sleep(1)
upload = self.web.find_element(By.XPATH, '//*[@id="exampleMOLFile"]')
self.wait.until(EC.presence_of_element_located((By.XPATH, upload_xpath)))
upload = self.web.find_element(By.XPATH, upload_xpath)
try:
upload.send_keys(pdb_dir)
submit = self.web.find_element(By.XPATH, "/html/body/div[2]/div/div[2]/form/button[1]")
Expand All @@ -133,7 +136,7 @@ def data_from_smiles(self, smiles_code):
Args:
smiles_code: The SMILES code for the LigParGen input.
"""
self.web.get("http://zarbi.chem.yale.edu/ligpargen/")
self.web.get("http://traken.chem.yale.edu/ligpargen/")
time.sleep(1)
smile = self.web.find_element(By.XPATH, '//*[@id="smiles"]')
smile.send_keys(smiles_code)
Expand All @@ -155,9 +158,9 @@ def download_data(self, lmp_name: str):
"""
print("Structure info uploaded. Rendering force field...")
lmp_xpath = "/html/body/div[2]/div[2]/div[1]/div/div[14]/form/input[1]"
jmol_xpath = self.web.find_element(By.XPATH, "/html/body/div[2]/div[2]/div[2]")
self.wait.until(EC.presence_of_element_located((By.XPATH, lmp_xpath)))
self.web.execute_script("arguments[0].remove();", jmol_xpath)
jmol = self.web.find_element(By.XPATH, "/html/body/div[2]/div[2]/div[2]")
self.web.execute_script("arguments[0].remove();", jmol)
self.wait.until(EC.element_to_be_clickable((By.XPATH, lmp_xpath)))
data_lmp = self.web.find_element(By.XPATH, lmp_xpath)
num_file = len([f for f in os.listdir(self.write_dir) if os.path.splitext(f)[1] == ".lmp"]) + 1
Expand Down
12 changes: 11 additions & 1 deletion mdgo/residence_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
This module calculates species correlation lifetime (residence time).
"""
import os
from typing import List, Dict, Union, Tuple

import numpy as np
Expand Down Expand Up @@ -171,6 +172,7 @@ def fit_residence_time(
acf_avg_dict: Dict[str, np.ndarray],
cutoff_time: int,
time_step: float,
save_curve: Union[str, bool] = False,
) -> Dict[str, np.floating]:
"""
Use the ACF to fit the residence time (Exponential decay constant).
Expand All @@ -181,6 +183,8 @@ def fit_residence_time(
acf_avg_dict: A dict containing the ACFs of the species.
cutoff_time: Fitting cutoff time.
time_step: The time step between each frame, in ps.
save_curve: Whether to save the curve as a csv file for post-processing.
Default to False.
Returns:
A dict containing residence time of each species
Expand Down Expand Up @@ -217,7 +221,13 @@ def fit_residence_time(
fitted_y,
)
)
np.savetxt(f"/Users/th/Downloads/decay{i}.csv", save_decay.T, delimiter=",")
if save_curve:
if save_curve is True:
np.savetxt(f"decay{i}.csv", save_decay.T, delimiter=",")
elif os.path.exists(str(save_curve)):
np.savetxt(str(save_curve) + f"decay{i}.csv", save_decay.T, delimiter=",")
else:
raise ValueError("Please specify a bool or a path in string.")
plt.plot(
fitted_x,
fitted_y,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[tool.black]
line-length = 120
target-version = ['py38']
target-version = ['py310']
include = '\.pyi?$'
exclude = '''
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ numpy>=1.16.0
pandas
monty
pubchempy
pymatgen>=2022.7.8
pymatgen
scipy
selenium
setuptools
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
if __name__ == "__main__":
setup(
name="mdgo",
version="0.3.0",
version="0.3.1",
description="A codebase for MD simulation setup and results analysis.",
long_description=readme,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 1830b92

Please sign in to comment.