Skip to content

Commit

Permalink
Adding maps to PDB react-router scenes and tidying before I move to m…
Browse files Browse the repository at this point in the history
…y own branch on github and use pull requests.
  • Loading branch information
martinemnoble1 committed Jan 11, 2024
1 parent 9f27e7a commit 040320e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package-lock.json
public/baby-gru/*
dist/*
node_modules/*
node_modules/*
**/.DS_Store
100 changes: 81 additions & 19 deletions src/MoorhenRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { MoorhenContainer, MoorhenMolecule, addMolecule } from 'moorhen'
import { MoorhenContainer, MoorhenMolecule, MoorhenMap, addMolecule, addMap, setActiveMap } from 'moorhen'
import { webGL } from 'moorhen/types/mgWebGL';
import { moorhen } from 'moorhen/types/moorhen';
import { useEffect, useRef } from 'react';
Expand All @@ -10,35 +10,93 @@ export const MoorhenRouter: React.FC = () => {
return <RouterProvider router={moorhenRouter} />
};

const MoorhenContainerWithPdb: React.FC = () => {
const WrappedMoorhenContainer: React.FC = () => {
const glRef = useRef<webGL.MGWebGL | null>(null)
const commandCentre = useRef<moorhen.CommandCentre | null>(null)
const dispatch = useDispatch()
const cootInitialized = useSelector((state: moorhen.State) => state.generalStates.cootInitialized)
const urlPrefix = ""
const urlPrefix: string = ""

const { pdbId } = useParams()
const { pdbId, tutorialNumber } = useParams()

const collectedProps = {
glRef, commandCentre, urlPrefix
}

const tutorialMtzColumnNames: { [key: string]: any } = {
1: { F: "FWT", PHI: "PHWT", Fobs: 'FP', SigFobs: 'SIGFP', FreeR: 'FREE' },
2: { F: "FWT", PHI: "PHWT", Fobs: 'FP', SigFobs: 'SIGFP', FreeR: 'FREE' },
3: { F: "FWT", PHI: "PHWT", Fobs: 'F', SigFobs: 'SIGF', FreeR: 'FREER' }
}

const loadTutorial = async (tutorialNumber: string) => {
const newMolecule = new MoorhenMolecule(commandCentre, glRef, "")
const newMap = new MoorhenMap(commandCentre, glRef)
const newDiffMap = new MoorhenMap(commandCentre, glRef)
await newMolecule.loadToCootFromURL(`${urlPrefix}/baby-gru/tutorials/moorhen-tutorial-structure-number-${tutorialNumber}.pdb`, `mol-${tutorialNumber}`)
await newMolecule.fetchIfDirtyAndDraw('CBs')
dispatch(addMolecule(newMolecule))
await newMolecule.centreOn('/*/*/*/*', false)
await newMap.loadToCootFromMtzURL(
`${urlPrefix}/baby-gru/tutorials/moorhen-tutorial-map-number-${tutorialNumber}.mtz`,
`map-${tutorialNumber}`,
{ isDifference: false, useWeight: false, calcStructFact: true, ...tutorialMtzColumnNames[tutorialNumber] }
)
await newDiffMap.loadToCootFromMtzURL(
`${urlPrefix}/baby-gru/tutorials/moorhen-tutorial-map-number-${tutorialNumber}.mtz`,
`diff-map-${tutorialNumber}`,
{ F: "DELFWT", PHI: "PHDELWT", isDifference: true, useWeight: false }
)
dispatch(addMap(newMap))
dispatch(addMap(newDiffMap))
dispatch(setActiveMap(newMap))
}

const loadPdb = async (pdbId: string) => {
const newMolecule: moorhen.Molecule = new MoorhenMolecule(commandCentre, glRef, "")
const pdbCode: string = pdbId.toLowerCase()
const coordUrl: string = `https://www.ebi.ac.uk/pdbe/entry-files/download/${pdbCode}.cif`
await newMolecule.loadToCootFromURL(coordUrl, pdbCode)
await newMolecule.addRepresentation("CRs", "/*/*")
await newMolecule.fetchIfDirtyAndDraw("ligands")
newMolecule.centreOn("/*/*")
glRef.current?.setZoom(4.0)
dispatch(addMolecule(newMolecule))
const newMap = new MoorhenMap(commandCentre, glRef)
const newDiffMap = new MoorhenMap(commandCentre, glRef)
try {
await newMap.loadToCootFromMapURL(
`https://www.ebi.ac.uk/pdbe/entry-files/${pdbCode}.ccp4`,
`${pdbCode}-2FoFc`,
false
)
dispatch(addMap(newMap))
}
catch (err) {
}
try {
await newDiffMap.loadToCootFromMapURL(
`https://www.ebi.ac.uk/pdbe/entry-files/${pdbCode}_diff.ccp4`,
`${pdbCode}-FoFc`,
true
)
dispatch(addMap(newDiffMap))
}
catch (err) {
}
}

useEffect(() => {
if (pdbId && cootInitialized) {
const asyncFunc = async () => {
const newMolecule: moorhen.Molecule = new MoorhenMolecule(commandCentre, glRef, "")
const pdbCode: string = pdbId.toLowerCase()
const coordUrl: string = `https://www.ebi.ac.uk/pdbe/entry-files/download/${pdbCode}.cif`
await newMolecule.loadToCootFromURL(coordUrl, pdbCode)
await newMolecule.addRepresentation("CRs", "/*/*")
await newMolecule.fetchIfDirtyAndDraw("ligands")
newMolecule.centreOn("/*/*")
glRef.current?.setZoom(4.0)
dispatch(addMolecule(newMolecule))
if (cootInitialized) {
if (pdbId) {
loadPdb(pdbId)
}
else if (tutorialNumber) {
loadTutorial(tutorialNumber)
}
asyncFunc()
}
}, [pdbId, cootInitialized])
}, [pdbId, tutorialNumber, cootInitialized])

return <MoorhenContainer {...collectedProps} />
}

Expand All @@ -54,11 +112,15 @@ const moorhenRouter = createBrowserRouter(
},
{
path: "/pdb/:pdbId",
element: <MoorhenContainerWithPdb />,
element: <WrappedMoorhenContainer />,
},
{
path: "/:pdbId",
element: <MoorhenContainerWithPdb />,
element: <WrappedMoorhenContainer />,
},
{
path: "/tutorial/:tutorialNumber",
element: <WrappedMoorhenContainer />,
},
]
)
Expand Down

0 comments on commit 040320e

Please sign in to comment.