Repository navigation
feat: get_density_from_cloud() COD workflow #331
Description
Activity
@yucongalicechen I deleted some of the discussion comments that are now out of date based on your edits and so leaving them is confusing
OK, Now I comment on your comment. I agree with this basically, but here is a preferred way if it is possible:
Proposed steps:- 1. Initialize a
str = ase.Atomsstructure using the given chemical formula - 2. get structure data from COD database (initially)
1. extract hill formulastr.hill_formula
2. formulate a COD request
3. execute the request - 7. Return the average density
There is no automated way to load from JSON payload into ASE. This is something we could think about requesting in ASE (they have such a thing for materials project) so it looks like the easiest is to temporarily write and read a cif file (ChatGPT answer):
import urllib.request from ase.io import read import os def load_cod_structure(cod_id: int): cif_url = f"https://www.crystallography.net/cod/{cod_id:07d}.cif" cif_file = f"{cod_id}.cif" # Download CIF file urllib.request.urlretrieve(cif_url, cif_file) # Read into ASE atoms = read(cif_file) # Clean up if desired os.remove(cif_file) return atoms # Example usage atoms = load_cod_structure(1000001) atomsOurs would look a bit different because of handling the filter and getting multiple responses, but I think we should go with this for now, at risk of it having somewhat poor performance.
We could think about caching to speed things up. ASE seems to have a database capability so we could save structure objects given a composition request. Let's not implement that until we find the performance is low. We could make an issue now though.
We could also make an issue to implement an interface to materials project. We would have to handle MP API keys in our config. If there was a MP api key that we can access we could search MP. Please make an issue for this, but again, this can wait for the future.
- 1. Initialize a
Problem:
User enters a chemical formula (e.g. SiO2, Nacl) and optionally a phase. The function returns the material density.
Proposed steps:
ase.Atoms?) using the given chemical formula and optional phase information.Atoms.hill_formula) to compute the Hill notation for the chemical formula and attach it to the structure object.Atoms.info["cod_entries"].density = (Z * molar_mass) / (volume_cm3 * AVOGADRO_NUMBER).@sbillinge I edited the tasks based on our discussion today. Please take a look and let me know if everything looks good :) I might close some of the current PRs to keep the commiting history clean. Thanks!