Molecular graph editing method and device and electronic equipment
By dissociating multiple structural factors from the molecular diagram and using an expert module for a perception mechanism, the problem of distribution offset in molecular diagram editing was solved, enabling accurate editing under different user expressions.
Patent Information
- Application Number
- CN202511381059.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-25
- Publication Date
- 2025-12-30
AI Technical Summary
Existing molecular diagram editing methods are prone to distribution shifts when faced with different users expressing the same target needs, resulting in editing results that do not meet user expectations.
By dissociating multiple structural factors from the molecular diagram to be edited, editing is performed using the perception mechanism between expert modules and structural factors. Multiple latent factors are introduced for semantic decomposition, and precise editing is achieved through cross-attention mechanism and large language model.
It enables accurate editing of molecular structures when faced with new combinations of attributes, avoiding distribution shifts and improving the accuracy and adaptability of molecular diagram editing.
Smart Images

Figure CN121237259A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of molecular design technology, and in particular to a method, apparatus, and electronic device for editing molecular diagrams. Background Technology
[0002] In the field of molecular design and drug discovery, molecular map editing (i.e., purposeful modification of molecular map structures) is a core task. Its purpose is to structurally adjust molecules according to user-specified goals, thereby meeting multiple physicochemical property constraints such as improving drug activity, improving solubility, and reducing toxicity.
[0003] However, in practical applications, researchers often propose new combinations of optimization objectives or express the same objective requirement using different descriptive languages. In such scenarios, the actual molecular diagram editing purpose required by the user is often not achieved, for example, deviations occur in the molecular diagram editing. Summary of the Invention
[0004] According to a first aspect of this disclosure, a molecular diagram editing method is provided, the method comprising: Receive an initial molecular diagram and a text instruction corresponding to the initial molecular diagram, the text instruction being used to instruct the initial molecular diagram to be edited; The initial molecular graph is decoupled to extract structural factors corresponding to various molecular properties, and the graph structure vectors of the structural factors are obtained. Based on the perception mechanism between multiple preset expert modules and the structural factors, multiple target expert modules that perceive the structural factors are used to edit multiple graph structure vectors in accordance with the text instructions to obtain the edited molecular graph. Among them, multiple expert modules correspond to various structural factors.
[0005] In an exemplary embodiment, the decoupling of the initial molecular graph and extraction of structural factors corresponding to various different molecular properties includes: The initial molecular diagram is input into a factor extraction model, which is used to extract structural factors belonging to different molecular properties from the initial molecular diagram. The factor extraction model is obtained by training a preset factor extraction model using multiple molecular map samples as training samples.
[0006] In an exemplary embodiment, obtaining the graph structure vector of the structure factor includes: The structural factors are input into a feature extraction model, which is based on a cross-attention mechanism to extract features from multiple structural factors to obtain the graph structure vector. Obtain the graph structure vector output by the feature extraction model; The feature extraction model and the factor extraction model are obtained in the same training session.
[0007] In an exemplary embodiment, the factor extraction model includes multiple sub-networks, each corresponding to a variety of molecular properties; Among these, the molecular properties include at least toxicity, solubility, and difficulty of synthesis; The step of inputting the initial molecular map into the factor extraction model includes: The initial molecular graph is input into multiple subnetworks of the factor extraction model to deconstruct a structural factor of a property from the initial molecular graph using the subnetworks.
[0008] In an exemplary embodiment, the step of utilizing a perception mechanism between multiple preset expert modules and the structural factors, and using multiple target expert modules that have perceived the structural factors to edit multiple graph structure vectors in accordance with the text instructions to obtain an edited molecular graph, includes: The text instructions and multiple graph structure vectors are input into the graph editing model; wherein, the graph editing model includes a perception module and multiple preset expert modules, and the perception module is used to select multiple target expert modules based on the text instructions and the graph structure factors; Obtain the molecular graph output by the graph editing model as the edited molecular graph; The graph editing model is obtained by training a large language model using multiple text samples and graph structure vector samples corresponding to each text sample as training samples. The graph structure vector sample is a vector corresponding to multiple structural factors deconstructed from the molecular graph sample.
[0009] In an exemplary embodiment, the method further includes: Obtain multiple first-molecule map samples; Using multiple samples of the first molecular graph as training samples, a preset model is trained to obtain a factor extraction model and a feature extraction model connected to the factor extraction model; the feature extraction model is used to extract features from multiple structural factors extracted by the factor extraction model based on a cross-attention mechanism. Multiple second molecular map samples are input into the factor extraction model to obtain multiple structural factor samples corresponding to each second molecular map sample; Multiple structural factor samples are input into the feature extraction model to obtain the graph structure vector samples.
[0010] In an exemplary embodiment, the selection module includes a dynamic gating network.
[0011] In an exemplary embodiment, the preset expert module is located in the feedforward network of the graph editing model and is configured as a LoRA parameter block in the graph editing model.
[0012] A second aspect of this disclosure provides a molecular map editing apparatus, the apparatus comprising: The data receiving module is used to receive an initial molecular diagram and a text instruction corresponding to the initial molecular diagram, wherein the text instruction is used to instruct the initial molecular diagram to be edited. The factor extraction module is used to decouple the initial molecular graph, extract structural factors corresponding to various different molecular properties, and obtain the graph structure vector of the structural factors. An editing module is used to edit multiple graph structure vectors corresponding to the text instructions based on the perception mechanism between multiple preset expert modules and the structural factors, using multiple target expert modules that have perceived the structural factors, to obtain an edited molecular graph. Among them, multiple expert modules correspond to various structural factors.
[0013] A third aspect of this disclosure provides an electronic device including a processor and a memory, the memory storing a program or instructions executable on the processor, the program or instructions, when executed by the processor, implementing the steps of the molecular diagram editing method as described in any of the first aspects.
[0014] The above description is merely an overview of the technical solution disclosed herein. In order to better understand the technical means of this disclosure and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this disclosure more apparent and understandable, specific embodiments of this disclosure are described below. Attached Figure Description
[0015] To more clearly illustrate the technical solutions in the embodiments or related technologies of this disclosure, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. It should be noted that the scale in the drawings is for illustration only and does not represent the actual scale.
[0016] Figure 1 Several illustrative representations of molecular diagrams are shown; Figure 2 An exemplary diagram illustrates the process of editing a molecular diagram; Figure 3 This diagram illustrates the steps of the molecular diagram editing method in this embodiment. Figure 4 A schematic diagram illustrating the process of obtaining structural factors is shown. Figure 5 A schematic diagram illustrating graph editing using a model is shown; Figure 6 A schematic diagram of the training process of the graph editing model is shown; Figure 7 A simplified structural schematic diagram of a molecular diagram editing device is shown. Detailed Implementation
[0017] To make the above-mentioned objectives, features, and advantages of this disclosure more apparent and understandable, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this disclosure. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0018] In recent years, Large Language Models (LLMs) have been explored for graph editing tasks due to their superior natural language understanding and generation capabilities, particularly in "text-instruction driven molecular optimization" applications that aim to control molecular structure transformations through natural language commands. However, most existing mainstream methods rely on the task distribution that has appeared in the training set, assuming that the training and test data come from the same distribution.
[0019] However, this doesn't hold true in practical applications. For example, researchers often propose new combinations of optimization objectives or express the same objective requirement in different natural language. For instance, even with the same phrase "reduce solubility," different users may express it differently. This leads to a "distribution shift" problem, causing the actual molecular map editing results to deviate from the user's expectations.
[0020] In view of this, embodiments of this disclosure propose a molecular diagram editing method, apparatus, and electronic device. The molecular diagram editing method mainly decomposes multiple structural factors from the molecular diagram to be edited. These multiple structural factors can correspond to different molecular properties. Thus, multiple "potential factors" are introduced into the molecular diagram to be edited to perform semantic decomposition of the structure, so that the decomposed structural factors can be matched with the input text instructions from a more refined perspective, avoiding the problem of distribution offset caused by different descriptions of the input text instructions.
[0021] On the other hand, through the perception mechanism between the expert module and the structural factor, the dissociated structural factor can be linked with multiple expert modules, so that the molecular structure can still be accurately and effectively edited when encountering new attribute combinations.
[0022] The molecular map editing method, apparatus, and electronic device of this disclosure will now be described by way of example with reference to the accompanying drawings.
[0023] Please combine Figure 1 , Figure 2 and Figure 3 As shown, Figure 1 Several examples of molecular diagram representations are shown. Figure 2 An exemplary diagram illustrates the process of editing a molecular graph. Figure 2 A schematic flowchart of the molecular diagram editing method of this embodiment is shown, as follows: Figure 1 and Figure 2 As shown, the method may include: Step S101: Receive an initial molecular diagram and a text instruction corresponding to the initial molecular diagram, wherein the text instruction is used to instruct the initial molecular diagram to be edited; Step S102: Decouple the initial molecular graph, extract the structural factors corresponding to various different molecular properties, and obtain the graph structure vector of the structural factors; Step S103: Based on the perception mechanism between multiple preset expert modules and the structural factors, multiple target expert modules that have perceived the structural factors are used to edit multiple graph structure vectors in accordance with the text instructions to obtain the edited molecular graph; Among them, multiple expert modules correspond to various structural factors.
[0024] In this embodiment, the initial molecular diagram can refer to the molecular diagram to be edited.
[0025] Molecular diagrams are a graphical method for characterizing molecular structures in chemistry. They describe molecular features through the topological relationships between atoms (nodes) and chemical bonds (edges) and are commonly used for the analysis of conjugated systems. In this embodiment, the structural characterization is simplified by removing non-essential components, and Hückel parameters such as charge density and bond order can be labeled to reflect the characteristics of electron distribution.
[0026] like Figure 1 As shown, the molecular diagram can be Figure 1 As shown in (1), or, the molecular diagram can be as follows: Figure 1 As shown in (2). Among them, Figure 1 The molecular graph shown in (2) is of type Graph. Specifically, the molecular graph consists of multiple nodes and edges connecting the multiple nodes. Nodes can be represented as molecules, and edges can be represented as bonds between molecules.
[0027] In this embodiment, an initial molecular diagram to be edited and a text instruction corresponding to the initial molecular diagram can be received. The text instruction can be described in natural language, which may include text instructions described in multiple languages such as Chinese and English.
[0028] The text command type can be txt, etc., which will not be elaborated here.
[0029] Text commands can be typed by the user through the input device of an electronic device.
[0030] Text commands can be used to instruct the editing of an initial molecular diagram, specifically to edit the chemical structure of the initial molecular diagram. For example, text commands can be used to instruct changes to bond interactions, polarity, solubility, etc. In drug design, text commands can also be used to instruct binding affinity, target selectivity, etc.
[0031] In step S102, multiple structural factors can be extracted from the initial molecular diagram. Each structural factor can correspond to one or more molecular properties, and different structural factors can correspond to different molecular properties.
[0032] Among these, molecular properties can include toxicity, solubility, synthesis difficulty, polarity, and other attributes.
[0033] For example, with Figure 2 For example, different structural factors can be decomposed from the molecular diagram, and different structural factors can have the same nodes or different nodes.
[0034] Specifically, structural factors of as many molecular properties as possible can be extracted from the initial molecular diagram.
[0035] The structural factor can be understood as a subgraph in the initial molecular graph, containing a portion of the content in the initial molecular graph.
[0036] After obtaining the structural factors, feature extraction can be performed on multiple structural factors to obtain graph structure vectors of the structural factors. When obtaining the graph structure vectors, the correlation between multiple structural factors can be constructed. This allows characterizing the correlation between structural factors with different molecular properties. This correlation can include the importance / influence of a structural factor of one molecular property on a structural factor of another molecular property.
[0037] In some examples, the graph structure vector of the structure factor can be extracted using a cross-attention mechanism.
[0038] In this way, when obtaining the graph structure vector, the structure factors (belonging to the Graph) and text instructions can be aligned in the same feature space, so that data of different modalities (text instruction data and Graph data) can be processed in the same feature space.
[0039] In step S103, the expert module can be used to re-edit the corresponding graph structure vectors based on keywords in the text instructions to obtain new graph structure vectors. In this way, multiple new graph structure vectors can form a new molecular graph.
[0040] In this system, an expert module can be bound to a structural factor, and different expert modules can be bound to different structural factors.
[0041] One structural factor can be bound to multiple expert modules, each of which is adept at executing different editing instructions (text instructions).
[0042] In this embodiment, the perception mechanism between multiple preset expert modules and structural factors can refer to the binding relationship between multiple structural factors of the initial molecular map and multiple expert modules. Based on this binding relationship, multiple target expert modules associated with structural factors can be obtained.
[0043] In some examples, the target expert module can also be jointly perceived based on the input text instructions and the input graph structure vector. In this way, the target expert module can be an expert module that is bound to the graph structure vector (i.e., structure factor) and is good at processing the editing instructions indicated by the text instructions.
[0044] In this embodiment, the target expert module can be used to edit multiple graph structure vectors according to text commands to obtain the edited molecular graph.
[0045] Among them, multiple keywords related to molecular diagram editing can be extracted from the text commands. For example, "reduce" and "solubility" are keywords in "reduce solubility".
[0046] Next, based on the extracted keywords, feature extraction can be performed to obtain the feature vector of the input text instruction. When constructing this feature vector, a cross-attention mechanism can also be used to characterize the correlation between multiple keywords. For example, contextual information in the text instruction can be extracted, so that the feature vector can more accurately describe the text instruction, further avoiding the distribution shift problem caused by different description habits producing different text instructions.
[0047] In particular, when using the target expert module to edit multiple graph structure vectors corresponding to text instructions, multiple expert modules can edit multiple graph structure vectors based on the extracted keywords; because the structure vectors and keywords belong to the same feature space; This allows editing of the initial molecular diagram based on text instructions to be transformed into editing of one vector onto another, i.e., vector manipulation. In this way, the graph structure vector can be edited to obtain a new graph structure vector.
[0048] In some examples, multiple target expert modules can form a hybrid expert group. The hybrid expert group can jointly edit multiple graph structure vectors according to the text instructions. For example, the graph structure vectors edited by one target expert module can be merged, spliced, or added with the graph structure vectors edited by another target expert module. This makes the editing of graph structure vectors by multiple target expert modules not isolated, enhances the graph editing correlation between multiple target expert modules, and improves the accuracy of molecular graph editing.
[0049] The edited molecular graph is obtained by combining the edited graph structure vectors from multiple target expert modules.
[0050] In some examples, multiple target expert modules can be constructed into a neural network structure. In this way, multiple graph structure vectors and vectors corresponding to keywords in text instructions can be input into the neural network structure to obtain the edited graph structure vector. The edited graph structure vector can then be restored to a molecular graph to obtain the edited molecular graph.
[0051] The graph editing method employed in this embodiment, on the one hand, introduces multiple "latent factors" to semantically decompose the molecular graph to be edited. This allows the dissociated structural factors to be matched with the input text instructions from a more refined perspective, avoiding distribution shifts caused by inconsistencies in the descriptions of the input text instructions. On the other hand, through the perception mechanism between expert modules and structural factors, the dissociated structural factors can interact with multiple expert modules, enabling accurate and effective editing of the molecular structure even when encountering new attribute combinations.
[0052] In some embodiments, please refer to Figure 4 As shown, Figure 4 A schematic diagram of the process for obtaining structural factors is shown, such as Figure 4As shown, when decoupling the initial molecular graph and extracting structural factors corresponding to various different molecular properties, the initial molecular graph can be input into a factor extraction model. The factor extraction model is used to extract structural factors belonging to different molecular properties from the initial molecular graph. The factor extraction model is obtained by training a preset factor extraction model using various molecular graph samples as training samples.
[0053] In this embodiment, the training process of the factor extraction module is as follows: First, multiple molecular map samples are obtained, each targeting different molecular structures. For example, multiple molecular map samples can cover as many chemical structures as possible with molecular attributes, thereby improving the generalization performance of the factor extraction model.
[0054] Next, multiple molecular map samples are input into the preset factor extraction model in batches. The batch can contain n molecular map samples, where n can be 10 or 5, and there is no limitation here.
[0055] In this embodiment, during the training process, the preset factor extraction model can extract structural factors guided by a set of learnable prototype vectors, which can be continuously updated during the training process.
[0056] The training of the factor extraction module in this embodiment can be unsupervised. For example, during the training process, the performance of the preset factor extraction model can be evaluated based on multiple structural factors output by the preset factor extraction model, and the prototype vector of the preset factor extraction model can be updated.
[0057] For example, a loss function can be constructed based on multiple structural factors, which can characterize whether the extracted structural factors fully express the different molecular properties of the molecular structure.
[0058] When the preset factor extraction model converges, training can be terminated, and the preset factor extraction model at the end of training can be used as the factor extraction model.
[0059] Next, in the inference phase, the initial molecular diagram can be input into the factor extraction model. In this way, the factor extraction model can extract structural factors of different molecular properties from the initial molecular diagram.
[0060] In some examples of this embodiment, such as Figure 4 As shown, the factor extraction model includes multiple sub-networks, each corresponding to a variety of molecular properties; wherein, the various molecular properties include at least toxicity, solubility, and synthesis difficulty; Accordingly, when the initial molecular graph is input into the factor extraction model, the initial molecular graph can be input into multiple sub-networks of the factor extraction model to deconstruct a structural factor of a property from the initial molecular graph using the sub-networks.
[0061] like Figure 4 As shown, multiple subnetworks in the factor extraction model can be parallel subnetworks.
[0062] like Figure 4 As shown, different sub-networks can all be input into the initial molecular graph, and different sub-networks can extract structural factors with different molecular properties from the initial molecular graph.
[0063] In this example, the model parameters of different subnetworks may not be exactly the same.
[0064] In some examples of this embodiment, such as Figure 4 As shown, graph structure vectors can also be obtained through neural network models, such as constructing a model based on cross-attention mechanism, so as to extract graph structure vectors after extracting structural factors.
[0065] Specifically, when obtaining the graph structure vector of the structural factor, the structural factor can be input into a feature extraction model, which performs feature extraction on multiple structural factors based on a cross-attention mechanism to obtain the graph structure vector; and the graph structure vector output by the feature extraction model can be obtained. The feature extraction model and the factor extraction model are obtained in the same training session.
[0066] In this embodiment, the feature extraction model can be a transformer model. Thus, the structural factors can be extracted into graph structure vectors in the feature extraction model through a cross-attention mechanism.
[0067] In this embodiment, the feature extraction model can be trained together with the factor extraction model.
[0068] For example, such as Figure 4 As shown, the feature extraction model can be connected after the factor extraction model. During the training process, a loss function can be constructed based on the output graph structure vector, and the prototype vector in the factor extraction model and the parameters in the feature extraction model can be updated based on the loss value.
[0069] As described in the previous embodiments, the feature extraction model can characterize the correlation between structural factors of different molecular properties through the cross-attention mechanism, and can integrate cross-molecular property information within the molecular structure, thereby improving matching accuracy.
[0070] In some embodiments, when editing multiple graph structure vectors based on text instructions, a large language model can be used.
[0071] Please refer to Figure 5 As shown, Figure 5 A schematic diagram illustrating graph editing using a model is shown, such as... Figure 5 As shown, when using the perception mechanism between multiple preset expert modules and the structural factors, and using multiple target expert modules that perceive the structural factors to edit multiple graph structure vectors corresponding to the text instructions to obtain the edited molecular graph, the text instructions and the graph structure vectors can be input into the graph editing model; and the molecular graph output by the graph editing model can be obtained as the edited molecular graph. The graph editing model includes a perception module and multiple preset expert modules. The perception module is used to select multiple target expert modules based on the text instructions and the graph structure factors. The graph editing model is obtained by training a large language model using multiple text samples and graph structure vector samples corresponding to each text sample as training samples. Among them, the graph structure vector sample is a vector corresponding to multiple structural factors deconstructed from the molecular graph sample.
[0072] In this embodiment, the graph editing model can be a large language model, which includes multiple trained expert modules.
[0073] The graph editing model is used to edit the graph structure vector according to text instructions, thereby obtaining the edited molecular graph.
[0074] In some examples, the graph editing model may also include a text feature extraction module, which can be used to extract keywords from text instructions and obtain feature vectors of the keywords.
[0075] The training process of the graph editing model is as follows: First, multiple text samples and the corresponding graph structure vector samples for each text sample can be obtained; Graph structure vectors and text commands can be input into the graph editing model. This graph editing model can include multiple expert modules, and different expert modules can correspond to different structure factors.
[0076] The molecular graph samples used to train the large language model can be different from those used to train the factor extraction model, thereby improving the generalization performance of both the factor extraction model and the graph editing model.
[0077] Among them, the molecular graph samples used to train the large language model can be input into the trained factor extraction model and feature extraction model, and the graph structure vector output by the feature extraction model is used as the graph structure vector sample of the first molecular graph sample.
[0078] The process of obtaining the graph structure vector samples can be referenced from the process of obtaining the graph structure vectors of the initial molecular graph, and will not be elaborated here.
[0079] Next, the text samples and their corresponding graph structure vector samples can be input into the large language model. Based on the edited molecular graph output by the large language model and the label molecular graph corresponding to the first molecular graph sample, a loss function can be constructed.
[0080] Among them, the labeled molecular graph can be understood as the truth value of the edited molecular graph after the first molecular graph sample has been edited.
[0081] In this way, a loss function can be constructed to determine the difference between the edited molecular graph and the labeled molecular graph output by the large language model. Based on the difference, the parameters of the large language model can be updated, for example, the parameters of the text feature extraction module and the parameters of multiple expert modules in the large language model.
[0082] When the large language model converges, training can be terminated, and the large language model at the end of training can be used as the graph editing model.
[0083] In this way, during the inference phase, text commands and graph structure vectors corresponding to the initial molecular graph can be input into the graph editing model. For example, text commands can be input into the text feature extraction module, and graph structure vectors can be input into multiple expert modules.
[0084] In some examples of this embodiment, a factor extraction model can be trained first, and then the factor extraction model can be used to obtain graph structure vector samples corresponding to multiple molecular graph samples.
[0085] Reference Figure 6 As shown, a schematic diagram of the training process of the graph editing model is illustrated. Figure 6 As shown, the following processes may be included: First, obtain multiple first-molecule map samples; Next, using multiple samples of the first molecular graph as training samples, the preset model is trained to obtain a factor extraction model and a feature extraction model connected to the factor extraction model; the feature extraction model is used to extract features from multiple structural factors extracted by the factor extraction model based on a cross-attention mechanism. Then, multiple second molecular graph samples are input into the factor extraction model to obtain multiple structural factor samples corresponding to each second molecular graph sample; and multiple structural factor samples are input into the feature extraction model to obtain the graph structure vector samples.
[0086] In this embodiment, the first molecular graph sample can be the same as the molecular graph sample of the training factor extraction model described above.
[0087] Different first molecular map samples can target different molecular structures. For example, multiple first molecular map samples can cover the chemical structures of more molecular properties as much as possible, thereby improving the generalization performance of the factor extraction model.
[0088] like Figure 4 As shown, the preset model may include a factor extraction model (the same as the preset factor extraction model mentioned above) and a feature extraction model connected to the factor extraction model. The factor extraction model can be used to extract multiple structural factors from the first molecular graph sample, and the feature extraction model can perform feature extraction on multiple structural factors to obtain a graph structure vector.
[0089] In this implementation, multiple first molecular map samples can be input into the preset model in batches. Each batch can input n first molecular map samples, where n can be 10 or 5, and there is no limitation here.
[0090] In this embodiment, during the training process, the factor extraction model can extract structural factors guided by a set of learnable prototype vectors, which can be continuously updated during the training process.
[0091] The training of the preset model in this embodiment can be unsupervised. For example, during the training process, the performance of the preset model can be evaluated based on the graph structure vector output by the preset model, and the prototype vector of the preset model can be updated.
[0092] For example, a loss function can be constructed based on multiple graph structure vectors output by a preset model. This loss function can characterize whether the extracted structural factors fully express the different molecular properties of the molecular structure.
[0093] When the preset model converges, training can be terminated, and the preset model at the end of training can be used for subsequent inference.
[0094] Next, multiple second molecular graph samples can be input into the factor extraction model in the pre-trained preset model to obtain multiple structural factor samples corresponding to each second molecular graph sample; and the multiple structural factor samples can be input into the pre-trained feature extraction model to obtain the graph structure vector samples.
[0095] Then, the graph structure vector sample can be input together with the text sample into the large language model for training to obtain the graph editing model.
[0096] Using this embodiment, a factor extraction model and a feature extraction model can be pre-trained. Then, with the help of the factor extraction model and the feature extraction model, graph structure vector samples can be obtained to train the graph editing model.
[0097] In some examples of this embodiment, such as Figure 5 As shown, the selection module includes a dynamic gating network.
[0098] In this example, the graph editing model selects a hybrid expert combination suitable for the current input, which is the graph structure vector, through a dynamic gating layer.
[0099] In some examples of this embodiment, such as Figure 5 As shown, the preset expert module is located in the feedforward network of the graph editing model and is configured as the LoRA parameter block in the graph editing model.
[0100] In this example, multiple sets of LoRA parameter blocks are inserted into the feedforward module of the large language model to form a graph editing model, where each LoRA (low-rank adaptation) module only receives the graph features of its associated structural factors.
[0101] LoRA (Low-Rank Adaptation) is a fast fine-tuning method used to adapt large models to specific tasks and datasets. It can handle each task by integrating different neurons or features, allowing a single large language model (LLM) to be used for multiple tasks. By identifying and improving appropriate features from a large pool of features, we can obtain better results for a specific task.
[0102] The following is a complete description of an optional example of an embodiment of this disclosure.
[0103] S1: The factor extractor for training graph structure factors, i.e., the factor extraction model.
[0104] First, a set of multi-channel graph encoding networks is constructed, namely the preset factor extraction model mentioned above. The model can adopt a GNN (Graph Neural Network). Each sub-network extracts a potential structural factor of the molecular graph (e.g., related to attributes such as toxicity, solubility, and synthesis difficulty). These structural factors are guided by a set of learnable prototype vectors and extracted into graph structure vectors through a cross-attention mechanism (feature extraction model), which are then injected into the graph editing model as input.
[0105] This ensures that the structural semantic features extracted by the graph editing model are stable and generalizable, and decouples the attribute factors that can be called by subsequent modules.
[0106] S2: Training the graph editing model To enable the graph editing model to flexibly adapt to various text instructions, a factor-aware hybrid expert module based on LoRA was designed. Each expert module is bound to a structural factor and processes the text instructions corresponding to that structural factor. Multiple sets of LoRA parameter blocks are inserted into the feedforward module of the graph boundary model. Each LoRA module only receives the graph structure vector of its associated structural factor. The model selects the hybrid expert combination suitable for the current input through a dynamic gating layer. This achieves module-level semantic routing, allowing the graph editing model to adaptively combine multiple capabilities across different tasks, rather than forcibly sharing parameters.
[0107] This enhances the generalization ability of graph editing models under complex structure-attribute-language combinations and enables factor-level interpretable expert control.
[0108] S3: Input the initial molecular diagram to be edited into the factor extraction model to obtain multiple structural factors; S4: Input multiple structural factors into the feature extraction model to obtain the graph structure vector of multiple structural factors based on the cross attention mechanism; S5: Input multiple graph structure vectors and feature vectors corresponding to text instructions into the graph editing model. The graph editing model performs expert perception based on the input feature vectors and graph structure vectors. The gating network can send the graph structure vectors and feature vectors into a hybrid expert group composed of multiple target expert modules (which can be understood as a sub-neural network). Using this hybrid expert group, the model performs editing on multiple graph structure vectors corresponding to the feature vectors corresponding to the text instructions, and finally outputs the edited molecular graph.
[0109] The graph editing method presented in this example will provide crucial technical support for molecular graph editing in various practical scenarios such as new drug development and molecular design. It enables precise modification of molecular structures based on user natural language commands, achieving intelligent drug optimization and property control. It can address the challenges of diverse language commands and complex attribute combinations, demonstrating high generalization ability and strong practicality.
[0110] Furthermore, by fine-tuning the large language model to extract the structural factors corresponding to textual instructions, and combining this with a factor-aware expert module for graph editing, this method enables stable and accurate modification of molecular structures even in scenarios with distribution shifts. This approach not only enhances the understanding of complex language instructions but also provides an interpretable and controllable editing mechanism, greatly expanding the application scope and reliability of molecular graph editing methods in practical products.
[0111] The molecular diagram editing method described above can be applied to electronic devices such as computers, servers, and mobile phones.
[0112] Based on the same inventive concept, and referring to Figure 7 As shown, a molecular diagram editing device is also provided, such as Figure 7 As shown, the device includes: The data receiving module is used to receive an initial molecular diagram and a text instruction corresponding to the initial molecular diagram, wherein the text instruction is used to instruct the initial molecular diagram to be edited. The factor extraction module is used to decouple the initial molecular graph, extract structural factors corresponding to various different molecular properties, and obtain the graph structure vector of the structural factors. An editing module is used to edit multiple graph structure vectors corresponding to the text instructions based on the perception mechanism between multiple preset expert modules and the structural factors, using multiple target expert modules that have perceived the structural factors, to obtain an edited molecular graph. Among them, multiple expert modules correspond to various structural factors.
[0113] For example, the factor extraction module is specifically used to input the initial molecular map into the factor extraction model, and the factor extraction model is used to extract structural factors belonging to different molecular properties from the initial molecular map; The factor extraction model is obtained by training a preset factor extraction model using multiple molecular map samples as training samples.
[0114] Exemplarily, the device further includes: The structural factor input module is used to input the structural factors into the feature extraction model. The feature extraction model is based on the cross attention mechanism to extract features from multiple structural factors to obtain the graph structure vector. The graph structure vector acquisition module is used to acquire the graph structure vector output by the feature extraction model; The feature extraction model and the factor extraction model are obtained in the same training session.
[0115] For example, the factor extraction model includes multiple sub-networks, each corresponding to a variety of molecular properties; Among these, the molecular properties include at least toxicity, solubility, and difficulty of synthesis; The structure factor input module is specifically used to input the initial molecular graph into multiple sub-networks of the factor extraction model, so as to use the sub-networks to deconstruct a structure factor of a property from the initial molecular graph.
[0116] For example, the editing module includes: The first input module is used to input the text instructions and multiple graph structure factors into the graph editing model; wherein, the graph editing model includes a perception module and multiple preset expert modules, and the perception module is used to select multiple target expert modules based on the text instructions and the graph structure factors; The molecular diagram acquisition module is used to acquire the molecular diagram output by the diagram editing model as the edited molecular diagram; The graph editing model is obtained by training a large language model using multiple text samples and graph structure vector samples corresponding to each text sample as training samples. The graph structure vector sample is a vector corresponding to multiple structural factors deconstructed from the molecular graph sample.
[0117] Exemplarily, the device further includes: The first sample acquisition module is used to acquire various first molecular map samples; The training module is used to train a preset model using multiple first molecular map samples as training samples to obtain a factor extraction model and a feature extraction model connected to the factor extraction model; the feature extraction model is used to extract features from multiple structural factors extracted by the factor extraction model based on a cross-attention mechanism. The second input module is used to input multiple second molecular map samples into the factor extraction model to obtain multiple structural factor samples corresponding to each second molecular map sample. The third input module is used to input multiple structural factor samples into the feature extraction model to obtain the graph structure vector samples.
[0118] A third aspect of this disclosure provides an electronic device including a processor and a memory, the memory storing a program or instructions executable on the processor, the program or instructions, when executed by the processor, implementing the steps as described in the embodiments of the aforementioned molecular diagram editing method.
[0119] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0120] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0121] The present disclosure provides a detailed description of a molecular map editing method, apparatus, and electronic device. Specific examples have been used to illustrate the principles and implementation methods of the present disclosure. The descriptions of the above embodiments are only for the purpose of helping to understand the method and its core ideas. At the same time, those skilled in the art will recognize that there will be changes in the specific implementation methods and application scope based on the ideas of the present disclosure. Therefore, the content of this specification should not be construed as a limitation of the present disclosure.
[0122] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0123] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
[0124] The terms "an embodiment," "embodiment," or "one or more embodiments" as used herein mean that a particular feature, structure, or characteristic described in connection with an embodiment is included in at least one embodiment of this disclosure. Furthermore, please note that the examples of the phrase "in one embodiment" do not necessarily all refer to the same embodiment.
[0125] Numerous specific details are set forth in the specification provided herein. However, it will be understood that embodiments of this disclosure may be practiced without these specific details. In some instances, well-known methods, structures, and techniques have not been shown in detail so as not to obscure the understanding of this specification.
[0126] In the claims, any reference signs placed between parentheses should not be construed as limiting the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. This disclosure can be implemented by means of hardware comprising a plurality of different elements and by means of a suitably programmed computer. In a unit claim enumerating a plurality of means, several of these means may be embodied by the same item of hardware. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.
[0127] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this disclosure, and are not intended to limit them. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this disclosure.
Claims
1. A molecular graph editing method characterized by, The method comprises: receiving an initial molecular graph and a text instruction corresponding to the initial molecular graph, the text instruction being used to instruct graph editing on the initial molecular graph; decoupling the initial molecular graph, extracting structural factors corresponding to a plurality of different molecular properties, and obtaining graph structure vectors of the structural factors; based on a perception mechanism between a plurality of preset expert modules and the structural factors, using a plurality of target expert modules that perceive the structural factors to edit a plurality of the graph structure vectors corresponding to the text instruction, to obtain an edited molecular graph; wherein a plurality of the expert modules correspond to a plurality of structural factors respectively.
2. The molecular map editing method according to claim 1, wherein, The decoupling of the initial molecular graph, the extraction of structural factors corresponding to a plurality of different molecular properties, comprises: inputting the initial molecular graph into a factor extraction model, the factor extraction model being used to extract structural factors belonging to different molecular properties from the initial molecular graph; wherein the factor extraction model is obtained by training a preset factor extraction model using a plurality of molecular graph samples as training samples.
3. The molecular map editing method according to claim 2, wherein, The obtaining of the graph structure vectors of the structural factors comprises: inputting the structural factors into a feature extraction model, the feature extraction model being based on a cross-attention mechanism to extract features from a plurality of the structural factors, to obtain the graph structure vectors; obtaining the graph structure vectors output by the feature extraction model; wherein the feature extraction model and the factor extraction model are obtained in the same training.
4. The molecular map editing method according to claim 2, wherein, The factor extraction model comprises a plurality of sub-networks, and the plurality of sub-networks correspond to a plurality of molecular properties respectively; wherein the plurality of molecular properties at least include toxicity, solubility, and synthesis difficulty; The inputting of the initial molecular graph into the factor extraction model comprises: inputting the initial molecular graph into a plurality of the sub-networks of the factor extraction model, to use the sub-networks to deconstruct structural factors of one property from the initial molecular graph.
5. The molecular map editing method of claim 1, wherein, The use of a plurality of preset expert modules and the structural factors based on a perception mechanism, the use of a plurality of target expert modules that perceive the structural factors to edit a plurality of the graph structure vectors corresponding to the text instruction, to obtain an edited molecular graph, comprises: inputting the text instruction and a plurality of the graph structure vectors into a graph editing model; wherein the graph editing model comprises a perception module and a plurality of the preset expert modules, the perception module being used to select a plurality of the target expert modules based on the text instruction and the graph structure factors; obtaining a molecular graph output by the graph editing model as the edited molecular graph; wherein the graph editing model is obtained by training a large language model using a plurality of text samples and a plurality of graph structure vector samples corresponding to each of the text samples as training samples; wherein the graph structure vector sample is a vector corresponding to a plurality of structural factors deconstructed from a molecular graph sample.
6. The molecular map editing method according to claim 5, wherein, The method further comprises: obtaining a plurality of first molecular graph samples; The first plurality of molecular graph samples are used as training samples to train a preset model to obtain a factor extraction model and a feature extraction model connected to the factor extraction model; the feature extraction model is configured to perform feature extraction on the plurality of structural factors extracted by the factor extraction model based on a cross-attention mechanism; The second plurality of molecular graph samples are input into the factor extraction model to obtain a plurality of structural factor samples corresponding to each of the second plurality of molecular graph samples; The plurality of structural factor samples are input into the feature extraction model to obtain the graph structure vector sample.
7. The molecular map editing method according to claim 5, wherein, The selection module comprises a dynamic gating network.
8. The molecular map editing method of claim 5, wherein, The preset expert module is located in a feedforward network of the graph editing model and is configured as a LoRA parameter block in the graph editing model.
9. A molecular map editing apparatus characterized by comprising: The device comprises: a data receiving module configured to receive an initial molecular graph and a text instruction corresponding to the initial molecular graph, the text instruction being used to instruct graph editing of the initial molecular graph; a factor extraction module configured to decouple the initial molecular graph to extract structural factors corresponding to a plurality of different molecular attributes and obtain graph structure vectors of the structural factors; an editing module configured to perform editing corresponding to the text instruction on the plurality of graph structure vectors by using a plurality of target expert modules perceiving the structural factors based on a perception mechanism between a plurality of preset expert modules and the structural factors to obtain an edited molecular graph; wherein the plurality of expert modules correspond to the plurality of structural factors respectively.
10. An electronic device, comprising: The device comprises a processor and a memory, the memory storing programs or instructions executable on the processor, and the programs or instructions are executed by the processor to implement the steps of the molecular graph editing method according to any one of claims 1-8.