| import { getMoleculesFromStore } from "@/Store/StoreExternalAccess"; |
| import { selectInstructionsLong } from "@/UI/Navigation/TitleBar/MolSelecting"; |
| import { |
| SelectedType, |
| TreeNodeType, |
| } from "@/UI/Navigation/TreeView/TreeInterfaces"; |
| import { TreeNodeList } from "@/TreeNodes/TreeNodeList/TreeNodeList"; |
| import type { TreeNode } from "@/TreeNodes/TreeNode/TreeNode"; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function checkAnyMolSelected( |
| treeNodeList?: TreeNodeList, |
| noun = "molecule" |
| ): string | null { |
| const num = _numSelected(treeNodeList); |
| if (num === 0) { |
| return `No ${noun}s are currently selected. First select a ${noun} by clicking on its name in the Navigator panel.`; |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function checkAnyCompoundSelected( |
| treeNodeList?: TreeNodeList |
| ): string | null { |
| if (treeNodeList === undefined) { |
| treeNodeList = getMoleculesFromStore(); |
| } |
|
|
| const compounds = treeNodeList.flattened.filters.keepType( |
| TreeNodeType.Compound |
| ); |
| const selectedCompounds = compounds.filters.keepSelected(true); |
|
|
| if (selectedCompounds.length === 0) { |
| return "No compounds are currently selected. First select a compound by clicking on its name in the Navigator panel."; |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function checkOneMolSelected( |
| treeNodeList?: TreeNodeList |
| ): string | null { |
| const num = _numSelected(treeNodeList); |
| if (num !== 1) { |
| return "First select one (and only one) molecule by clicking on its name in the Navigator panel."; |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function checkMultipleMolsSelected( |
| treeNodeList?: TreeNodeList |
| ): string | null { |
| const num = _numSelected(treeNodeList); |
| if (num < 2) { |
| return `First select at least two molecules by clicking on their names in the Navigator panel. ${selectInstructionsLong}`; |
| |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| function _numSelected(treeNodeList?: TreeNodeList): number { |
| if (treeNodeList === undefined) { |
| treeNodeList = getMoleculesFromStore(); |
| } |
|
|
| |
| const selectedNodes = ( |
| treeNodeList as TreeNodeList |
| ).flattened.filters.keepSelected(SelectedType.True); |
| return selectedNodes.length; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function checkAnyMolLoaded(treeNodeList?: TreeNodeList): string | null { |
| if (treeNodeList === undefined) { |
| treeNodeList = getMoleculesFromStore(); |
| } |
|
|
| if ((treeNodeList as TreeNodeList).length === 0) { |
| return "No molecules are currently loaded (empty project). Try adding molecules first."; |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function _checkTypeLoaded( |
| type: TreeNodeType, |
| treeNodeList?: TreeNodeList |
| ): string | null { |
| if (treeNodeList === undefined) { |
| treeNodeList = getMoleculesFromStore(); |
| } |
|
|
| const entries = treeNodeList.flattened.filters.keepType(type); |
|
|
| if (entries.length === 0) { |
| return `No ${type} is currently loaded. Try adding a ${type} first.`; |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function checkProteinLoaded(treeNodeList?: TreeNodeList): string | null { |
| return _checkTypeLoaded(TreeNodeType.Protein, treeNodeList); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function checkProteinOrNucleicLoaded( |
| treeNodeList?: TreeNodeList |
| ): string | null { |
| if (treeNodeList === undefined) { |
| treeNodeList = getMoleculesFromStore(); |
| } |
| const proteins = treeNodeList.flattened.filters.keepType( |
| TreeNodeType.Protein |
| ); |
| const nucleicAcids = treeNodeList.flattened.filters.keepType( |
| TreeNodeType.Nucleic |
| ); |
|
|
| if (proteins.length === 0 && nucleicAcids.length === 0) { |
| return "No protein or nucleic acid is currently loaded. Try adding a receptor first."; |
| } |
| return null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function checkCompoundLoaded( |
| treeNodeList?: TreeNodeList |
| ): string | null { |
| return _checkTypeLoaded(TreeNodeType.Compound, treeNodeList); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function checkMultipleTopLevelProteinsLoaded( |
| treeNodeList?: TreeNodeList |
| ): string | null { |
| if (treeNodeList === undefined) { |
| treeNodeList = getMoleculesFromStore(); |
| } |
| let proteinContainerCount = 0; |
| |
| treeNodeList.forEach((topLevelNode: TreeNode) => { |
| |
| const flattenedDescendants = new TreeNodeList([topLevelNode]).flattened; |
| const hasProtein = flattenedDescendants.some( |
| (node) => node.type === TreeNodeType.Protein |
| ); |
| if (hasProtein) { |
| proteinContainerCount++; |
| } |
| }); |
| if (proteinContainerCount < 2) { |
| return "At least two molecules with protein components are required for alignment."; |
| } |
| return null; |
| } |
|
|