Single‑page app for visualizing crystal structures and metadata.
- React 18 + TypeScript + Vite + Material UI
- Renders 3D scenes from JSON using
@materialsproject/mp-react-components - Two input modes: Prompt or CIF upload (≤10MB)
- Loading and error handling with MUI components
Prerequisites:
- Node.js 18+ and npm
Install dependencies:
npm install
Start dev server:
npm run dev- Opens on an available port (e.g.,
http://localhost:5175)
Build for production:
npm run build
Preview the production build:
npm run preview(servesdistathttp://localhost:4173)
VITE_API_URL(default:http://localhost:8000)- Configure in an
.envfile or environment for the Vite dev server/build. - Local: set in
.env.local(already added) - Production: set in
.env.production(edit with your API URL) - After changing env files, restart dev server.
- Configure in an
Types used by the UI:
export type SceneResponse = {
scene: any;
formula: string;
lattice: {
a: number;
b: number;
c: number;
alpha: number;
beta: number;
gamma: number;
volume: number;
};
n_sites: number;
source: 'upload' | 'prompt';
};
Endpoints:
-
Upload:
POST {VITE_API_URL}/api/scene- multipart/form-data with field
file(CIF, ≤10MB) - Response:
SceneResponsewithsource: "upload"
- multipart/form-data with field
-
Prompt:
POST {VITE_API_URL}/api/prompt-structure- JSON body:
{ "prompt": string } 501or404indicates not implemented; UI shows:Prompt generation not available yet- Response:
SceneResponsewithsource: "prompt"
- JSON body:
- App bar and page title:
Lattice Lab - Left panel: Toggle between Prompt and Upload
- Prompt: Multiline
TextFieldwith placeholderDescribe the crystal you want…,Generatebutton - Upload: Drag & drop or select
.cif(≤10MB),Upload & Renderbutton
- Prompt: Multiline
- Right panel:
- Fixed-height viewer (~560px) that consumes Scene JSON directly via
CrystalToolkitScene - Metadata card showing: Formula, Number of sites, Lattice parameters (a, b, c, α, β, γ, volume), Source
- Fixed-height viewer (~560px) that consumes Scene JSON directly via
- Validation: Only
.cifaccepted; files over 10MB are blocked with an errorAlert - Loading:
LinearProgressshown during API calls - Errors: Surface API or validation issues via
Alert
src/App.tsx: Layout, UI logic, and state managementsrc/api.ts: API helpers (uploadCif,generateFromPrompt), defaultingVITE_API_URLsrc/types.ts:SceneResponsetype definitionsrc/types/mp-react-components.d.ts: Minimal type declaration for the scene viewer componentsrc/main.tsx,index.html,vite.config.ts: App bootstrap and tooling
- The 3D viewer expects the
scenefield to be a Crystal Toolkit Scene JSON object. If your backend differs, adapt the mapping before passing toCrystalToolkitScene. - If prompt generation is not implemented, the UI will show a friendly message and not fail the app.
- To test backend connectivity, set
VITE_API_URLand verify both endpoints return the expected JSON.