| <template> |
| <PluginComponent v-model="open" :infoPayload="infoPayload" actionBtnTxt="Merge" @onPopupDone="onPopupDone" |
| @onUserArgChanged="onUserArgChanged" @onMolCountsChanged="onMolCountsChanged"></PluginComponent> |
| </template> |
|
|
| <script lang="ts"> |
| |
| |
| import { Options } from "vue-class-component"; |
| import { |
| IContributorCredit, |
| ISoftwareCredit, |
| } from "@/Plugins/PluginInterfaces"; |
| |
| import { mergeTreeNodes } from "@/UI/Navigation/TreeView/TreeUtils"; |
| import PluginComponent from "@/Plugins/Parents/PluginComponent/PluginComponent.vue"; |
| import { PluginParentClass } from "@/Plugins/Parents/PluginParentClass/PluginParentClass"; |
| import { getDefaultNodeToActOn, setNodesToActOn } from "./EditBarUtils"; |
| import { checkMultipleMolsSelected } from "../../CheckUseAllowedUtils"; |
| import { UserArg, IUserArgText } from "@/UI/Forms/FormFull/FormFullInterfaces"; |
| import { ITest } from "@/Testing/TestInterfaces"; |
| import { TreeNodeList } from "@/TreeNodes/TreeNodeList/TreeNodeList"; |
| import { TreeNode } from "@/TreeNodes/TreeNode/TreeNode"; |
| import { getMoleculesFromStore } from "@/Store/StoreExternalAccess"; |
| import { treeNodeListDeepClone } from "@/TreeNodes/Deserializers"; |
| import { TestCmdList } from "@/Testing/TestCmdList"; |
| import { Tag } from "@/Plugins/Core/ActivityFocus/ActivityFocusUtils"; |
| |
| |
| |
| |
| @Options({ |
| components: { |
| PluginComponent, |
| }, |
| }) |
| export default class MergeMolsPlugin extends PluginParentClass { |
| menuPath = ["Edit", "Molecules", "[5] Merge..."]; |
| title = "Merge Molecules"; |
| softwareCredits: ISoftwareCredit[] = []; |
| contributorCredits: IContributorCredit[] = [ |
| // { |
| // name: "Jacob D. Durrant", |
| // url: "http://durrantlab.com/", |
| // }, |
| ]; |
| pluginId = "mergemols"; |
| intro = "Copy and merge the selected molecules into a single new molecule."; |
| details = "This plugin is useful for combining multiple structures, such as a protein and several ligands, into one entry."; |
| |
| userArgDefaults: UserArg[] = [ |
| { |
| id: "newName", |
| label: "", |
| val: "", |
| placeHolder: "Name of new merged molecule...", |
| description: "The name of the new, merged molecule.", |
| validateFunc: (newName: string): boolean => { |
| return newName.length > 0; |
| }, |
| } as IUserArgText, |
| ]; |
| |
| nodesToActOn = new TreeNodeList([getDefaultNodeToActOn()]); |
| |
| logJob = false; |
| tags = [Tag.All]; |
| |
| |
| |
| |
| |
| {any} payload The payload (node id) |
| */ |
| async onBeforePopupOpen(payload: any) { |
| setNodesToActOn(this, payload, true); |
| |
| // Generate the suggested title for merged molecule. |
| // Get top of molecule title. |
| let titles: string[] = []; |
| this.nodesToActOn.forEach((node) => { |
| const title = node |
| .getAncestry(this.$store.state.molecules as TreeNodeList) |
| .get(0).title; |
| titles.push(title); |
| }); |
| |
| |
| titles = titles.filter((title, index) => { |
| return titles.indexOf(title) === index; |
| }); |
| titles.sort(); |
| |
| this.setUserArg("newName", titles.join("-") + ":merged"); |
| } |
| |
| |
| |
| |
| {string | null} If it returns a string, show that as an error |
| * message. If null, proceed to run the plugin. |
| */ |
| checkPluginAllowed(): string | null { |
| return checkMultipleMolsSelected(); |
| } |
| |
| |
| |
| |
| |
| {Promise<void>} Resolves when the job is done. |
| */ |
| runJobInBrowser(): Promise<void> { |
| if (!this.nodesToActOn) { |
| // Nothing to do. |
| return Promise.resolve(); |
| } |
| |
| |
| |
| |
| return treeNodeListDeepClone(getMoleculesFromStore()) |
| .then((allNodes: TreeNodeList) => { |
| let idsToKeep: string[] = this.nodesToActOn.map((node) => { |
| return node.id; |
| }); |
| this.nodesToActOn.forEach((node) => { |
| node.getAncestry(allNodes).forEach((ancestor) => { |
| if (ancestor.id) { |
| idsToKeep.push(ancestor.id); |
| } |
| }); |
| }); |
| idsToKeep = idsToKeep.filter((id, index) => { |
| // only unique |
| return idsToKeep.indexOf(id) === index; |
| }); |
| const onlySelectedTreeNodeList = |
| allNodes.filters.onlyIdsDeep(idsToKeep); |
| |
| return mergeTreeNodes( |
| onlySelectedTreeNodeList, |
| this.getUserArg("newName") |
| ); |
| }) |
| .then((mergedTreeNode: TreeNode) => { |
| // this.$store.commit("pushToMolecules", mergedTreeNode); |
| mergedTreeNode.addToMainTree(this.pluginId); |
| return; |
| }) |
| .catch((err) => { |
| throw err; |
| }); |
| |
| |
| |
| { |
| // return mergeTreeNodes( |
| // treeNodeList, |
| // this.getUserArg("newName") |
| // ); |
| // }) |
| { |
| // this.$store.commit("pushToMolecules", mergedTreeNode); |
| // return; |
| // }) |
| { |
| // throw err; |
| // }); |
| } |
| |
| |
| |
| |
| |
| |
| {ITest[]} The selenium test commands. |
| */ |
| async getTests(): Promise<ITest[]> { |
| return [ |
| { |
| beforePluginOpens: () => new TestCmdList() |
| .loadExampleMolecule(true) |
| .selectMoleculeInTree("Protein") |
| .selectMoleculeInTree("Compounds", true), |
| pluginOpen: () => new TestCmdList().setUserArg("newName", "My-Merged-Molecule", this.pluginId), |
| afterPluginCloses: () => new TestCmdList().waitUntilRegex( |
| "#navigator", |
| "My-Merged-Molecule" |
| ), |
| }, |
| ]; |
| } |
| } |
| </script> |
| |
| <style scoped lang="scss"></style> |
|
|