Spaces:
Runtime error
Runtime error
File size: 5,353 Bytes
b489aa1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# NIST Chemical Kinetics API
This application provides both a web interface (Gradio) and a REST API (FastAPI) for searching and analyzing the NIST Chemical Kinetics Database.
## Access Points
- **Web Interface**: `http://localhost:7860/` (or your deployed URL)
- **API Documentation**: `http://localhost:7860/docs` (Swagger UI)
- **Alternative API Docs**: `http://localhost:7860/redoc` (ReDoc)
## API Endpoints
### 1. Root Information
```
GET /
```
Returns basic API information and available endpoints.
**Response:**
```json
{
"name": "NIST Chemical Kinetics API",
"version": "1.0.0",
"endpoints": {
"/search": "Search NIST kinetics database",
"/reaction/{url}": "Get detailed reaction information",
"/thermodynamic/{formula}": "Get thermodynamic data for a compound",
"/nist-reactions": "Get list of NIST reactions",
"/docs": "API documentation"
}
}
```
### 2. Search Reactions
```
POST /search
```
Search the NIST Chemical Kinetics Database.
**Parameters:**
- `query` (required): Search query string (e.g., "CH4", "benzene")
- `filters` (optional): Array of filter objects
**Request Body Example:**
```json
{
"query": "CH4",
"filters": [
{
"field": "reactants",
"relation": "contains",
"value": "CH4"
}
]
}
```
**Response Example:**
```json
{
"query": "CH4",
"count": 10,
"results": [
{
"reaction": "CH4 + OH β CH3 + H2O",
"k_298": "6.3e-15",
"a": "2.45e-12",
"n": "0.0",
"ea": "1710",
"t_range": "200-500 K",
"p_range": "0.001-100 atm",
"bath_gas": "He",
"url": "https://kinetics.nist.gov/..."
}
]
}
```
### 3. Get Reaction Detail
```
GET /reaction?url={nist_url}
```
Get detailed information for a specific reaction.
**Parameters:**
- `url` (required): NIST reaction URL
**Response Example:**
```json
{
"reaction": "CH4 + OH β CH3 + H2O",
"reactants": ["CH4", "OH"],
"products": ["CH3", "H2O"],
"rate_data": [
{
"k_298": "6.3e-15",
"a": "2.45e-12",
"n": "0.0",
"ea": "1710",
"t_range": "200-500 K",
"p_range": "0.001-100 atm",
"bath_gas": "He",
"reference": "Atkinson et al., 2004",
"squib": "2004ATK/BAU8400-8468"
}
]
}
```
### 4. Get Thermodynamic Data
```
GET /thermodynamic/{formula}?database={db_type}
```
Get thermodynamic data for a compound from NIST WebBook.
**Parameters:**
- `formula` (required): Chemical formula or name (e.g., "CH3", "benzene")
- `database` (optional): Database type - "gas-phase", "ion-energetics", or "condensed-phase" (default: "gas-phase")
**Response Example:**
```json
{
"formula": "CH3",
"database": "gas-phase",
"data": [
{
"Temperature (K)": 298.15,
"Cp (J/mol*K)": 38.70,
"S (J/mol*K)": 194.20,
"H-H298 (kJ/mol)": 0.0
}
],
"summary": "# Thermodynamic Data for CH3\n..."
}
```
### 5. Get NIST Reactions List
```
GET /nist-reactions?limit={number}
```
Get a list of reactions from the NIST database.
**Parameters:**
- `limit` (optional): Maximum number of reactions to return (default: 200)
**Response Example:**
```json
{
"count": 200,
"reactions": [
{
"label": "CH4 + OH β CH3 + H2O",
"reaction": "CH4 + OH β CH3 + H2O"
}
]
}
```
## Using the API
### cURL Examples
**Search for reactions:**
```bash
curl -X POST "http://localhost:7860/search?query=CH4" \
-H "Content-Type: application/json"
```
**Get reaction details:**
```bash
curl "http://localhost:7860/reaction?url=https://kinetics.nist.gov/kinetics/Detail?id=1993DEA/SIB4517-4529:4"
```
**Get thermodynamic data:**
```bash
curl "http://localhost:7860/thermodynamic/CH3?database=gas-phase"
```
**Get NIST reactions list:**
```bash
curl "http://localhost:7860/nist-reactions?limit=50"
```
### Python Example
```python
import requests
# Search for reactions
response = requests.post(
"http://localhost:7860/search",
params={"query": "CH4"}
)
data = response.json()
print(f"Found {data['count']} reactions")
# Get thermodynamic data
response = requests.get(
"http://localhost:7860/thermodynamic/benzene",
params={"database": "gas-phase"}
)
thermo_data = response.json()
print(thermo_data)
```
### JavaScript Example
```javascript
// Search for reactions
fetch('http://localhost:7860/search?query=CH4', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => console.log(`Found ${data.count} reactions`));
// Get thermodynamic data
fetch('http://localhost:7860/thermodynamic/benzene?database=gas-phase')
.then(response => response.json())
.then(data => console.log(data));
```
## Running the Application
```bash
# Install dependencies
pip install -r requirements.txt
# Run the application
python app.py
```
The application will start on `http://0.0.0.0:7860` by default. You can change the port by setting the `PORT` environment variable:
```bash
PORT=8000 python app.py
```
## Deployment
For production deployment, consider using:
- **Gunicorn** with Uvicorn workers
- **Docker** for containerization
- **Nginx** as a reverse proxy
Example with Gunicorn:
```bash
gunicorn app:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:7860
```
## License
Please refer to the NIST data usage policies and licensing terms when using this API.
|