| import { IMolsToConsider } from "@/FileSystem/LoadSaveMolModels/SaveMolModels/Types"; |
| import { compileMolModels } from "@/FileSystem/LoadSaveMolModels/SaveMolModels/SaveMolModels"; |
| import { TreeNodeList } from "@/TreeNodes/TreeNodeList/TreeNodeList"; |
| import { getConvertedTxts } from "@/FileSystem/LoadSaveMolModels/SaveMolModels/SaveMolModelsUtils"; |
| import { FileInfo } from "@/FileSystem/FileInfo"; |
| import { TreeNode } from "@/TreeNodes/TreeNode/TreeNode"; |
| import { TreeNodeType } from "@/UI/Navigation/TreeView/TreeInterfaces"; |
|
|
| export interface IMoleculeInputParams { |
| molsToConsider?: IMolsToConsider; |
| considerProteins?: boolean; |
| considerCompounds?: boolean; |
| proteinFormat?: string; |
| compoundFormat?: string; |
| includeMetalsAsProtein?: boolean; |
| includeSolventAsProtein?: boolean; |
| includeNucleicAsProtein?: boolean; |
| allowUserToToggleIncludeMetalsAsProtein?: boolean; |
| allowUserToToggleIncludeSolventAsProtein?: boolean; |
| allowUserToToggleIncludeNucleicAsProtein?: boolean; |
| |
| |
| |
| batchSize?: number | null | undefined; |
| } |
|
|
| export interface IProtCmpdTreeNodePair { |
| prot: FileInfo; |
| cmpd: FileInfo; |
| } |
|
|
| export interface IProtCmpdCounts { |
| compounds: number; |
| proteins: number; |
| } |
|
|
| |
| |
| |
| export class MoleculeInput { |
| molsToConsider = { |
| visible: true, |
| selected: false, |
| hiddenAndUnselected: false, |
| } as IMolsToConsider; |
| considerProteins = true; |
| considerCompounds = true; |
| includeMetalsAsProtein = true; |
| includeSolventAsProtein = true; |
| includeNucleicAsProtein = true; |
| allowUserToToggleIncludeMetalsAsProtein = true; |
| allowUserToToggleIncludeSolventAsProtein = true; |
| allowUserToToggleIncludeNucleicAsProtein = true; |
| proteinFormat = "pdb"; |
| compoundFormat = "mol2"; |
|
|
| |
| batchSize: number | null | undefined = undefined; |
|
|
| |
| |
| isMoleculeInput = true; |
|
|
| |
| |
| |
| |
| |
| |
| constructor(params?: IMoleculeInputParams) { |
| if (params === undefined) { |
| return; |
| } |
|
|
| if (params.molsToConsider !== undefined) { |
| this.molsToConsider = params.molsToConsider; |
| } |
| if (params.considerProteins !== undefined) { |
| this.considerProteins = params.considerProteins; |
| } |
| if (params.considerCompounds !== undefined) { |
| this.considerCompounds = params.considerCompounds; |
| } |
| if (params.proteinFormat !== undefined) { |
| this.proteinFormat = params.proteinFormat; |
| } |
| if (params.compoundFormat !== undefined) { |
| this.compoundFormat = params.compoundFormat; |
| } |
| if (params.includeMetalsAsProtein !== undefined) { |
| this.includeMetalsAsProtein = params.includeMetalsAsProtein; |
| } |
| if (params.includeSolventAsProtein !== undefined) { |
| this.includeSolventAsProtein = params.includeSolventAsProtein; |
| } |
| if (params.includeNucleicAsProtein !== undefined) { |
| this.includeNucleicAsProtein = params.includeNucleicAsProtein; |
| } |
| if (params.allowUserToToggleIncludeMetalsAsProtein !== undefined) { |
| this.allowUserToToggleIncludeMetalsAsProtein = |
| params.allowUserToToggleIncludeMetalsAsProtein; |
| } |
| if (params.allowUserToToggleIncludeSolventAsProtein !== undefined) { |
| this.allowUserToToggleIncludeSolventAsProtein = |
| params.allowUserToToggleIncludeSolventAsProtein; |
| } |
| if (params.allowUserToToggleIncludeNucleicAsProtein !== undefined) { |
| this.allowUserToToggleIncludeNucleicAsProtein = |
| params.allowUserToToggleIncludeNucleicAsProtein; |
| } |
| |
| if (params.batchSize !== undefined) { |
| this.batchSize = params.batchSize; |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| public getProtAndCompoundPairs(): Promise< |
| IProtCmpdTreeNodePair[] | FileInfo[] |
| |
| |
| > { |
| |
| |
| |
|
|
| |
| const compiledMols = compileMolModels(this.molsToConsider, true); |
|
|
| |
| if (!this.considerProteins) { |
| compiledMols.nodeGroups = []; |
| } |
| if (!this.considerCompounds) { |
| compiledMols.compoundsNodes = new TreeNodeList(); |
| } |
|
|
| const protFileInfoPromises = compiledMols.nodeGroups.map( |
| (prots: TreeNodeList) => { |
| |
| if (!this.includeMetalsAsProtein) { |
| prots = prots.filter( |
| (p: TreeNode) => |
| p.type !== TreeNodeType.Metal && |
| p.type !== TreeNodeType.Ions |
| ); |
| } |
| if (!this.includeSolventAsProtein) { |
| prots = prots.filter( |
| (p: TreeNode) => p.type !== TreeNodeType.Solvent |
| ); |
| } |
| if (!this.includeNucleicAsProtein) { |
| prots = prots.filter( |
| (p: TreeNode) => p.type !== TreeNodeType.Nucleic |
| ); |
| } |
|
|
| |
| return getConvertedTxts(prots, this.proteinFormat, true).then( |
| (fileInfos: FileInfo[]) => { |
| |
| return fileInfos[0]; |
| } |
| ); |
| } |
| ); |
|
|
| |
| let cmpdFileInfoPromise: Promise<any> = Promise.resolve(); |
| if (compiledMols.compoundsNodes) { |
| |
| cmpdFileInfoPromise = getConvertedTxts( |
| compiledMols.compoundsNodes, |
| this.compoundFormat, |
| false |
| ); |
| } |
|
|
| const allProtPromises = Promise.all(protFileInfoPromises); |
|
|
| |
|
|
| return Promise.all([allProtPromises, cmpdFileInfoPromise]) |
| .then((payload: FileInfo[][]) => { |
| let [prots, cmpds] = payload; |
|
|
| |
| |
| prots = prots.filter((p: FileInfo) => p !== undefined); |
| cmpds = cmpds.filter((c: FileInfo) => c !== undefined); |
|
|
| const proteinCompoundPairs: IProtCmpdTreeNodePair[] = []; |
| if (prots.length > 0 && cmpds.length > 0) { |
| |
| for (const prot of prots) { |
| for (const cmpd of cmpds) { |
| proteinCompoundPairs.push({ |
| prot: prot, |
| cmpd: cmpd, |
| } as IProtCmpdTreeNodePair); |
| } |
| } |
| |
| return proteinCompoundPairs; |
| } |
|
|
| if (cmpds.length > 0) { |
| |
| |
| return cmpds; |
| } |
|
|
| |
| return prots; |
| }) |
| .catch((err: Error) => { |
| throw err; |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| } |
|
|