|
1 | | -from typing import List |
2 | | - |
3 | | -from fastapi import Depends, FastAPI |
4 | | -from fastapi.responses import PlainTextResponse |
| 1 | +from fastapi import FastAPI |
5 | 2 | from fastapi_pagination import add_pagination |
6 | | -from fastapi_pagination.cursor import CursorPage |
7 | | -from sqlmodel import Session |
8 | 3 |
|
9 | | -from .crud import ( |
10 | | - get_crystal_structure, |
11 | | - get_crystal_structures, |
12 | | - get_fdmnes_jobfile, |
13 | | - get_fdmnes_output, |
14 | | - get_fdmnes_simulation, |
15 | | - get_fdmnes_xas, |
16 | | - get_molecular_structure, |
17 | | - get_molecular_structures, |
18 | | - get_orca_jobfile, |
19 | | - get_orca_output, |
20 | | - get_orca_simulation, |
21 | | - get_orca_xas, |
22 | | - get_simulation, |
23 | | - get_simulations_page, |
24 | | - submit_fdmnes_simulation, |
25 | | - submit_orca_simulation, |
26 | | - upload_crystal_structure, |
27 | | - upload_molecular_structure, |
28 | | -) |
29 | | -from .database import get_session |
30 | | -from .models.models import ( |
31 | | - CrystalStructure, |
32 | | - CrystalStructureInput, |
33 | | - FdmnesSimulation, |
34 | | - FdmnesSimulationInput, |
35 | | - FdmnesSimulationResponse, |
36 | | - MolecularStructure, |
37 | | - MolecularStructureInput, |
38 | | - OrcaSimulation, |
39 | | - OrcaSimulationInput, |
40 | | - OrcaSimulationResponse, |
41 | | - SimulationResponse, |
42 | | -) |
| 4 | +from .routers import crystals, fdmnes, molecules, orca, simulations |
43 | 5 |
|
44 | 6 | app = FastAPI() |
45 | 7 |
|
46 | | -add_pagination(app) |
47 | | - |
48 | | - |
49 | | -@app.get("/api/simulations") |
50 | | -def get_simulations_pagination_endpoint( |
51 | | - session: Session = Depends(get_session), |
52 | | -) -> CursorPage[SimulationResponse]: |
53 | | - return get_simulations_page(session) |
54 | | - |
55 | | - |
56 | | -@app.get("/api/simulations/{id}") |
57 | | -def get_simulation_endpoint( |
58 | | - id: int, session: Session = Depends(get_session) |
59 | | -) -> SimulationResponse: |
60 | | - return get_simulation(session, id) |
61 | | - |
62 | | - |
63 | | -@app.post("/api/submit/orca") |
64 | | -def submit_orca( |
65 | | - orca_input: OrcaSimulationInput, |
66 | | - session: Session = Depends(get_session), |
67 | | -) -> OrcaSimulation: |
68 | | - return submit_orca_simulation(orca_input, session) |
69 | | - |
70 | | - |
71 | | -@app.get("/api/orca/{id}") |
72 | | -def get_orca_simulation_endpoint( |
73 | | - id: int, session: Session = Depends(get_session) |
74 | | -) -> OrcaSimulationResponse: |
75 | | - return get_orca_simulation(session, id) |
76 | | - |
77 | | - |
78 | | -# TODO actually implement |
79 | | -@app.get("/api/orca/{id}/output") |
80 | | -def get_orca_output_endpoint(id: int, session: Session = Depends(get_session)) -> str: |
81 | | - return PlainTextResponse(get_orca_output(session, id)) |
82 | | - |
83 | | - |
84 | | -# TODO replace with an actual implementation |
85 | | -@app.get("/api/orca/{id}/jobfile") |
86 | | -def get_orca_jobfile_endpoint(id: int, session: Session = Depends(get_session)) -> str: |
87 | | - return PlainTextResponse(get_orca_jobfile(session, id)) |
88 | | - |
89 | | - |
90 | | -# TODO further orca endpoint |
91 | | -# mapspc |
92 | | -# @app.get("/api/orca/{id}/spectra") |
93 | | -# @app.get("/api/orca/{id}/spectra/{spectrum_id}") |
94 | | -# request new mapspc call |
95 | | -# @app.post("/api/orca/{id}/spectra/") |
96 | | -# orbital cube files |
97 | | -# @app.get("/api/orca/{id}/orbitals") |
98 | | -# @app.get("/api/orca/{id}/orbitals/{orbital_calculation_id}") |
99 | | -# request new mapspc call |
100 | | -# @app.post("/api/orca/{id}/orbitals/") |
101 | | - |
102 | | - |
103 | | -@app.get("/api/molecules/{id}") |
104 | | -def get_molecular_endpoint( |
105 | | - id: int, session: Session = Depends(get_session) |
106 | | -) -> MolecularStructure: |
107 | | - return get_molecular_structure(session, id) |
108 | | - |
109 | | - |
110 | | -@app.post("/api/molecules") |
111 | | -def upload_molecular_endpoint( |
112 | | - structure: MolecularStructureInput, session: Session = Depends(get_session) |
113 | | -) -> MolecularStructure: |
114 | | - return upload_molecular_structure(structure, session) |
| 8 | +app.include_router(orca.router) |
| 9 | +app.include_router(fdmnes.router) |
| 10 | +app.include_router(molecules.router) |
| 11 | +app.include_router(crystals.router) |
| 12 | +app.include_router(simulations.router) |
115 | 13 |
|
116 | | - |
117 | | -@app.get("/api/molecules") |
118 | | -def get_molecular_list_endpoint( |
119 | | - session: Session = Depends(get_session), |
120 | | -) -> List[MolecularStructure]: |
121 | | - return get_molecular_structures(session) |
122 | | - |
123 | | - |
124 | | -@app.get("/api/crystals/{id}") |
125 | | -def get_crystal_endpoint( |
126 | | - id: int, session: Session = Depends(get_session) |
127 | | -) -> CrystalStructure: |
128 | | - return get_crystal_structure(session, id) |
129 | | - |
130 | | - |
131 | | -@app.post("/api/crystals") |
132 | | -def upload_crystal_endpoint( |
133 | | - structure: CrystalStructureInput, session: Session = Depends(get_session) |
134 | | -) -> CrystalStructure: |
135 | | - return upload_crystal_structure(structure, session) |
136 | | - |
137 | | - |
138 | | -@app.get("/api/crystals") |
139 | | -def get_crystal_list_endpoint( |
140 | | - session: Session = Depends(get_session), |
141 | | -) -> List[CrystalStructure]: |
142 | | - return get_crystal_structures(session) |
143 | | - |
144 | | - |
145 | | -@app.post("/api/submit/fdmnes") |
146 | | -def submit_fdmnes( |
147 | | - fdmnes_input: FdmnesSimulationInput, |
148 | | - session: Session = Depends(get_session), |
149 | | -) -> FdmnesSimulation: |
150 | | - return submit_fdmnes_simulation(fdmnes_input, session) |
151 | | - |
152 | | - |
153 | | -@app.get("/api/fdmnes/{id}") |
154 | | -def get_fdmnes_simulation_endpoint( |
155 | | - id: int, session: Session = Depends(get_session) |
156 | | -) -> FdmnesSimulationResponse: |
157 | | - return get_fdmnes_simulation(session, id) |
158 | | - |
159 | | - |
160 | | -@app.get("/api/fdmnes/{id}/jobfile") |
161 | | -def get_fdmnes_jobfile_endpoint( |
162 | | - id: int, session: Session = Depends(get_session) |
163 | | -) -> str: |
164 | | - return PlainTextResponse(get_fdmnes_jobfile(session, id)) |
165 | | - |
166 | | - |
167 | | -@app.get("/api/fdmnes/{id}/output") |
168 | | -def get_fdmnes_output_endpoint(id: int, session: Session = Depends(get_session)) -> str: |
169 | | - return PlainTextResponse(get_fdmnes_output(session, id)) |
170 | | - |
171 | | - |
172 | | -@app.get("/api/fdmnes/{id}/xas") |
173 | | -def get_fdmnes_xas_endpoint(id: int, session: Session = Depends(get_session)): |
174 | | - return get_fdmnes_xas(session, id) |
175 | | - |
176 | | - |
177 | | -@app.get("/api/orca/{id}/xas") |
178 | | -def get_orca_xas_endpoint(id: int, session: Session = Depends(get_session)): |
179 | | - return get_orca_xas(session, id) |
| 14 | +add_pagination(app) |
0 commit comments