|
5 | 5 |
|
6 | 6 | import numpy as np |
7 | 7 | import requests |
8 | | -from bs4 import BeautifulSoup |
9 | 8 | from scipy.optimize import dual_annealing |
10 | 9 | from scipy.signal import convolve |
11 | 10 | from xraydb import material_mu |
@@ -235,31 +234,17 @@ def fetch_cif_filenames(hill_formula): |
235 | 234 | ------ |
236 | 235 | ValueError |
237 | 236 | If no CIF files are found for the given formula. |
238 | | -
|
239 | | - Notes |
240 | | - ----- |
241 | | - The data is retrieved from the Crystallography Open Database (COD). |
242 | | - If you use COD data in your research, |
243 | | - please acknowledge the COD project as described at |
244 | | - https://www.crystallography.net/cod/acknowledgements.html. |
245 | 237 | """ |
246 | | - search_url = ( |
247 | | - f"https://www.crystallography.net/cod/" |
248 | | - f"result.php?formula={hill_formula}" |
249 | | - ) |
250 | | - response = requests.get(search_url) |
| 238 | + base_url = "https://www.crystallography.net/cod/result.php" |
| 239 | + params = {"formula": hill_formula, "format": "json"} |
| 240 | + response = requests.get(base_url, params=params) |
251 | 241 | if response.status_code != 200: |
252 | 242 | raise Exception( |
253 | 243 | f"Failed to retrieve search results. " |
254 | 244 | f"HTTP status code: {response.status_code}." |
255 | 245 | ) |
256 | | - cif_links = BeautifulSoup(response.text, "html.parser").find_all("a") |
257 | | - cif_filenames = [] |
258 | | - for link in cif_links: |
259 | | - href = link.get("href", "") |
260 | | - if href.endswith(".cif"): |
261 | | - filename = href.split("/")[-1] |
262 | | - cif_filenames.append(filename) |
| 246 | + data = response.json() |
| 247 | + cif_filenames = [str(entry["file"]) + ".cif" for entry in data] |
263 | 248 | if len(cif_filenames) == 0: |
264 | 249 | raise ValueError( |
265 | 250 | f"No CIF files found for the given formula: {hill_formula}. " |
|
0 commit comments