| import { MoleculeInput, IMoleculeInputParams } from "./MoleculeInput"; |
| import { getMoleculesFromStore } from "@/Store/StoreExternalAccess"; |
| import { TreeNode } from "@/TreeNodes/TreeNode/TreeNode"; |
| import { TreeNodeList } from "@/TreeNodes/TreeNodeList/TreeNodeList"; |
| import { |
| IAtom, |
| SelectedType, |
| TreeNodeType, |
| } from "@/UI/Navigation/TreeView/TreeInterfaces"; |
| import { convertFileInfosOpenBabel } from "@/FileSystem/OpenBabel/OpenBabel"; |
| import { FileInfo } from "@/FileSystem/FileInfo"; |
|
|
| |
| jest.mock("@/Store/StoreExternalAccess", () => ({ |
| getMoleculesFromStore: jest.fn(), |
| })); |
|
|
| jest.mock("@/FileSystem/OpenBabel/OpenBabel", () => ({ |
| convertFileInfosOpenBabel: jest.fn(), |
| })); |
|
|
| |
| |
| jest.mock( |
| "@/FileSystem/LoadSaveMolModels/ParseMolModels/ParseMolModelsUtils", |
| () => ({ |
| parseMolecularModelFromTexts: jest.fn().mockImplementation(() => { |
| |
| |
| const { |
| TreeNodeList, |
| } = require("@/TreeNodes/TreeNodeList/TreeNodeList"); |
| return Promise.resolve(new TreeNodeList([])); |
| }), |
| }) |
| ); |
|
|
| describe("MoleculeInput component filtering", () => { |
| beforeEach(() => { |
| |
| (getMoleculesFromStore as jest.Mock).mockClear(); |
| (convertFileInfosOpenBabel as jest.Mock).mockClear(); |
|
|
| |
| |
| (convertFileInfosOpenBabel as jest.Mock).mockImplementation( |
| async (fileInfos: FileInfo[], targetFormat: string) => { |
| |
| if ( |
| targetFormat === "pdb" || |
| targetFormat === "pdbqt" || |
| targetFormat === "pdbqtlig" |
| ) { |
| return fileInfos.map((fi) => fi.contents); |
| } |
| return []; |
| } |
| ); |
|
|
| |
| |
| const proteinAtom: IAtom = { |
| serial: 1, |
| atom: "CA", |
| resn: "GLY", |
| chain: "A", |
| resi: 1, |
| elem: "C", |
| x: 1, |
| y: 1, |
| z: 1, |
| bonds: [], |
| bondOrder: [], |
| }; |
| const metalAtom: IAtom = { |
| serial: 2, |
| atom: "ZN", |
| resn: "ZN", |
| chain: "A", |
| resi: 201, |
| elem: "ZN", |
| hetflag: true, |
| x: 2, |
| y: 2, |
| z: 2, |
| bonds: [], |
| bondOrder: [], |
| }; |
| const solventAtom: IAtom = { |
| serial: 3, |
| atom: "O", |
| resn: "HOH", |
| chain: "A", |
| resi: 301, |
| elem: "O", |
| hetflag: true, |
| x: 3, |
| y: 3, |
| z: 3, |
| bonds: [], |
| bondOrder: [], |
| }; |
| const nucleicAtom: IAtom = { |
| serial: 4, |
| atom: "P", |
| resn: "A", |
| chain: "B", |
| resi: 1, |
| elem: "P", |
| x: 4, |
| y: 4, |
| z: 4, |
| bonds: [], |
| bondOrder: [], |
| }; |
|
|
| |
| const proteinTerminalNode = new TreeNode({ |
| title: "Protein Chain A", |
| type: TreeNodeType.Protein, |
| model: [proteinAtom], |
| visible: true, |
| selected: SelectedType.False, |
| treeExpanded: false, |
| focused: false, |
| viewerDirty: false, |
| src: "test.pdb", |
| }); |
| const metalTerminalNode = new TreeNode({ |
| title: "ZN", |
| type: TreeNodeType.Metal, |
| model: [metalAtom], |
| visible: true, |
| selected: SelectedType.False, |
| treeExpanded: false, |
| focused: false, |
| viewerDirty: false, |
| src: "test.pdb", |
| }); |
| const solventTerminalNode = new TreeNode({ |
| title: "HOH", |
| type: TreeNodeType.Solvent, |
| model: [solventAtom], |
| visible: true, |
| selected: SelectedType.False, |
| treeExpanded: false, |
| focused: false, |
| viewerDirty: false, |
| src: "test.pdb", |
| }); |
| const nucleicTerminalNode = new TreeNode({ |
| title: "NA Chain B", |
| type: TreeNodeType.Nucleic, |
| model: [nucleicAtom], |
| visible: true, |
| selected: SelectedType.False, |
| treeExpanded: false, |
| focused: false, |
| viewerDirty: false, |
| src: "test.pdb", |
| }); |
|
|
| |
| const rootNode = new TreeNode({ |
| title: "MyMolecule", |
| visible: true, |
| selected: SelectedType.False, |
| treeExpanded: true, |
| focused: false, |
| viewerDirty: false, |
| nodes: new TreeNodeList([ |
| proteinTerminalNode, |
| metalTerminalNode, |
| solventTerminalNode, |
| nucleicTerminalNode, |
| ]), |
| src: "test.pdb", |
| }); |
|
|
| proteinTerminalNode.parentId = rootNode.id; |
| metalTerminalNode.parentId = rootNode.id; |
| solventTerminalNode.parentId = rootNode.id; |
| nucleicTerminalNode.parentId = rootNode.id; |
|
|
| const mockMolecules = new TreeNodeList([rootNode]); |
| (getMoleculesFromStore as jest.Mock).mockReturnValue(mockMolecules); |
| }); |
|
|
| it("should include protein, metal, solvent, and nucleic acid by default", async () => { |
| const params: IMoleculeInputParams = { |
| considerProteins: true, |
| considerCompounds: false, |
| proteinFormat: "pdb", |
| |
| }; |
| const moleculeInput = new MoleculeInput(params); |
| const result = |
| (await moleculeInput.getProtAndCompoundPairs()) as FileInfo[]; |
|
|
| expect(result).toHaveLength(1); |
| const pdbContent = result[0].contents; |
| expect(pdbContent).toMatch(/ATOM\s+.*\s+CA\s+GLY\s+/); |
| expect(pdbContent).toMatch(/HETATM\s+.*\s+ZN\s+ZN\s+/); |
| expect(pdbContent).toMatch(/HETATM\s+.*\s+O\s+HOH\s+/); |
| expect(pdbContent).toMatch(/HETATM\s+.*\s+P\s+A\s+/); |
| }); |
|
|
| it("should exclude metals when includeMetalsAsProtein is false", async () => { |
| const params: IMoleculeInputParams = { |
| considerProteins: true, |
| considerCompounds: false, |
| proteinFormat: "pdb", |
| includeMetalsAsProtein: false, |
| includeSolventAsProtein: true, |
| }; |
| const moleculeInput = new MoleculeInput(params); |
| const result = |
| (await moleculeInput.getProtAndCompoundPairs()) as FileInfo[]; |
| expect(result).toHaveLength(1); |
| const pdbContent = result[0].contents; |
| expect(pdbContent).toMatch(/ATOM\s+.*\s+CA\s+GLY\s+/); |
| expect(pdbContent).not.toMatch(/HETATM\s+.*\s+ZN\s+ZN\s+/); |
| expect(pdbContent).toMatch(/HETATM\s+.*\s+O\s+HOH\s+/); |
| expect(pdbContent).toMatch(/HETATM\s+.*\s+P\s+A\s+/); |
| }); |
|
|
| it("should exclude solvent when includeSolventAsProtein is false", async () => { |
| const params: IMoleculeInputParams = { |
| considerProteins: true, |
| considerCompounds: false, |
| proteinFormat: "pdb", |
| includeMetalsAsProtein: true, |
| includeSolventAsProtein: false, |
| }; |
| const moleculeInput = new MoleculeInput(params); |
| const result = |
| (await moleculeInput.getProtAndCompoundPairs()) as FileInfo[]; |
| expect(result).toHaveLength(1); |
| const pdbContent = result[0].contents; |
| expect(pdbContent).toMatch(/ATOM\s+.*\s+CA\s+GLY\s+/); |
| expect(pdbContent).toMatch(/HETATM\s+.*\s+ZN\s+ZN\s+/); |
| expect(pdbContent).not.toMatch(/HETATM\s+.*\s+O\s+HOH\s+/); |
| expect(pdbContent).toMatch(/HETATM\s+.*\s+P\s+A\s+/); |
| }); |
|
|
| it("should exclude nucleic acids when includeNucleicAsProtein is false", async () => { |
| const params: IMoleculeInputParams = { |
| considerProteins: true, |
| considerCompounds: false, |
| proteinFormat: "pdb", |
| includeNucleicAsProtein: false, |
| }; |
| const moleculeInput = new MoleculeInput(params); |
| const result = |
| (await moleculeInput.getProtAndCompoundPairs()) as FileInfo[]; |
| expect(result).toHaveLength(1); |
| const pdbContent = result[0].contents; |
| expect(pdbContent).toMatch(/ATOM\s+.*\s+CA\s+GLY\s+/); |
| expect(pdbContent).toMatch(/HETATM\s+.*\s+ZN\s+ZN\s+/); |
| expect(pdbContent).toMatch(/HETATM\s+.*\s+O\s+HOH\s+/); |
| expect(pdbContent).not.toMatch(/HETATM\s+.*\s+P\s+A\s+/); |
| }); |
|
|
| it("should exclude both metal and solvent when both flags are false", async () => { |
| const params: IMoleculeInputParams = { |
| considerProteins: true, |
| considerCompounds: false, |
| proteinFormat: "pdb", |
| includeMetalsAsProtein: false, |
| includeSolventAsProtein: false, |
| }; |
| const moleculeInput = new MoleculeInput(params); |
| const result = |
| (await moleculeInput.getProtAndCompoundPairs()) as FileInfo[]; |
| expect(result).toHaveLength(1); |
| const pdbContent = result[0].contents; |
| expect(pdbContent).toMatch(/ATOM\s+.*\s+CA\s+GLY\s+/); |
| expect(pdbContent).not.toMatch(/HETATM\s+.*\s+ZN\s+ZN\s+/); |
| expect(pdbContent).not.toMatch(/HETATM\s+.*\s+O\s+HOH\s+/); |
| expect(pdbContent).toMatch(/HETATM\s+.*\s+P\s+A\s+/); |
| }); |
| }); |
|
|