Skip to content

Commit

Permalink
Merge pull request #21 from htz1992213/main
Browse files Browse the repository at this point in the history
Fix PubchemRunner
  • Loading branch information
htz1992213 authored Nov 9, 2023
2 parents de354fb + 4ab4d4d commit ce8411e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 8 additions & 4 deletions mdgo/forcefield/pubchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(
"profile.managed_default_content_settings.images": 2,
}
self.options = webdriver.ChromeOptions()
self.server = webdriver.ChromeService(chromedriver_dir)
self.options.add_argument(
'user-agent="Mozilla/5.0 '
"(Macintosh; Intel Mac OS X 10_14_6) "
Expand All @@ -79,7 +80,7 @@ def __init__(
self.options.add_argument("--headless")
self.options.add_experimental_option("prefs", self.preferences)
self.options.add_experimental_option("excludeSwitches", ["enable-automation"])
self.web = webdriver.Chrome(chromedriver_dir, options=self.options)
self.web = webdriver.Chrome(options=self.options, service=self.server)
self.wait = WebDriverWait(self.web, 10)
self.web.get("https://pubchem.ncbi.nlm.nih.gov/")
time.sleep(1)
Expand Down Expand Up @@ -144,7 +145,8 @@ def _obtain_entry_web(self, search_text: str, name: str, output_format: str) ->
query = quote(search_text)
url = "https://pubchem.ncbi.nlm.nih.gov/#query=" + query
self.web.get(url)
time.sleep(1)
loaded_element_path = '//*[@id="main-results"]/div[1]/div/ul'
self.wait.until(EC.presence_of_element_located((By.XPATH, loaded_element_path)))
best_xpath = '//*[@id="featured-results"]/div/div[2]' "/div/div[1]/div[2]/div[1]/a/span/span"
relevant_xpath = (
'//*[@id="collection-results-container"]'
Expand All @@ -155,10 +157,12 @@ def _obtain_entry_web(self, search_text: str, name: str, output_format: str) ->
match = self.web.find_element(By.XPATH, best_xpath)
else:
match = self.web.find_element(By.XPATH, relevant_xpath)
self.wait.until(EC.element_to_be_clickable(match))
match.click()
time.sleep(1)
# density_locator = '//*[@id="Density"]/div[2]/div[1]/p'
cid_locator = '//*[@id="main-content"]/div/div/div[1]/' "div[3]/div/table/tbody/tr[1]/td"
smiles_locator = '//*[@id="Canonical-SMILES"]/div[2]/div[1]/p'
cid_locator = '//*[@id="Title-and-Summary"]/div/div/div/div[1]/div[2]'
smiles_locator = '//*[@id="Canonical-SMILES"]/div[2]/div[1]'
self.wait.until(EC.presence_of_element_located((By.XPATH, cid_locator)))
cid = self.web.find_element(By.XPATH, cid_locator).text
smiles = self.web.find_element(By.XPATH, smiles_locator).text
Expand Down
3 changes: 1 addition & 2 deletions mdgo/util/packmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
import subprocess
from pathlib import Path
from typing import Dict, List, Optional, Union

from pymatgen.core import Molecule
from shutil import which
from pymatgen.core import Molecule

# from pymatgen.io.core import InputFile, InputSet, InputGenerator

Expand Down

0 comments on commit ce8411e

Please sign in to comment.