get_sdf_pubchem_database_molecules
esta.lib_xyz.get_sdf_pubchem_database_molecules
¶
PubChem Molecular Structure Downloader¶
This script downloads: - Molecular 3D coordinates - Atomic labels (element symbols) - SDF structure files - Optional PDB files - Basic molecular metadata
Supported molecules: CO2, H2O, NH3, H2S, CH4, etc.
Main Goal: Retrieve full structural coordinate data for molecules.
Output: - Individual SDF files - Combined CSV summary - Parsed atomic coordinates
Author: OpenAI ChatGPT
MOLECULE_LIST = ['C2H6', 'C6H6']
module-attribute
¶
============================================================¶
Common Small Molecules List¶
============================================================¶
Format:¶
(Common_Name, Chemical_Formula)¶
small_molecules = [
# Water and simple inorganic molecules
("Water", "H2O"),
("Carbon dioxide", "CO2"),
("Carbon monoxide", "CO"),
("Oxygen", "O2"),
("Ozone", "O3"),
("Nitrogen", "N2"),
("Nitric oxide", "NO"),
("Nitrogen dioxide", "NO2"),
("Nitrous oxide", "N2O"),
("Ammonia", "NH3"),
("Hydrogen sulfide", "H2S"),
("Sulfur dioxide", "SO2"),
("Sulfur trioxide", "SO3"),
("Hydrogen chloride", "HCl"),
("Hydrogen fluoride", "HF"),
("Hydrogen bromide", "HBr"),
("Hydrogen iodide", "HI"),
("Methane", "CH4"),
("Ethane", "C2H6"),
("Propane", "C3H8"),
("Butane", "C4H10"),
# Alcohols
("Methanol", "CH3OH"),
("Ethanol", "C2H5OH"),
("Isopropanol", "C3H8O"),
# Simple organics
("Formaldehyde", "CH2O"),
("Acetaldehyde", "C2H4O"),
("Acetone", "C3H6O"),
("Formic acid", "CH2O2"),
("Acetic acid", "C2H4O2"),
("Oxalic acid", "C2H2O4"),
("Urea", "CH4N2O"),
# Hydrocarbons
("Ethylene", "C2H4"),
("Acetylene", "C2H2"),
("Benzene", "C6H6"),
("Toluene", "C7H8"),
# Cyanides and nitriles
("Hydrogen cyanide", "HCN"),
("Acetonitrile", "C2H3N"),
# Halogenated compounds
("Chloroform", "CHCl3"),
("Carbon tetrachloride", "CCl4"),
("Dichloromethane", "CH2Cl2"),
# Biological / atmospheric small molecules
("Hydrogen peroxide", "H2O2"),
("Phosphine", "PH3"),
("Hydrogen", "H2"),
("Helium", "He"),
("Argon", "Ar"),
("Neon", "Ne"),
# Sulfur compounds
("Carbonyl sulfide", "COS"),
("Carbon disulfide", "CS2"),
# Miscellaneous
("Hydrazine", "N2H4"),
("Nitromethane", "CH3NO2"),
("Glycine", "C2H5NO2"),
]
============================================================¶
Example Usage¶
============================================================¶
for name, formula in small_molecules: print(f"{name:20s} -> {formula}")
safe_request(url: str, binary: bool = False)
¶
Handles: - Retries - Rate limits - Temporary failures
get_cid(molecule: str) -> Optional[int]
¶
Finds PubChem CID from molecule name/formula.
download_sdf(cid: int, molecule: str) -> Optional[Path]
¶
Downloads 3D SDF structure file. Falls back to 2D if 3D unavailable.
download_pdb(cid: int, molecule: str) -> Optional[Path]
¶
Downloads PDB structure if available.
parse_sdf_coordinates(sdf_path: Path) -> List[Dict]
¶
Extracts: - X - Y - Z - Atomic symbol
save_summary(records: List[Dict])
¶
Saves summary information for all molecules.