Powder x-ray diffraction crystal structure retrieval method and system based on contrast learning

By employing a crystal structure retrieval method enhanced by comparative learning and multidimensional physical perturbation, the reliance on prior knowledge and vulnerability to experimental perturbation in existing technologies are addressed. This enables accurate identification of high-throughput crystal structures and recognition of unknown phases, while also meeting the scalability requirements of large-scale databases.

CN122135831APending Publication Date: 2026-06-02INST OF ENERGY HEFEI COMPREHENSIVE NAT SCI CENT (ANHUI ENERGY LAB)

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
INST OF ENERGY HEFEI COMPREHENSIVE NAT SCI CENT (ANHUI ENERGY LAB)
Filing Date
2026-05-07
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

Existing technologies for crystal structure identification suffer from a strong reliance on prior knowledge, vulnerability to experimental physical disturbances, and a lack of out-of-distribution detection capabilities, making it difficult to achieve accurate crystal structure identification in high-throughput scenarios.

Method used

A contrastive learning-based approach was adopted to construct a crystal embedding library. The library was retrieved using a PXRD encoder combined with a cosine similarity algorithm. A multi-dimensional physical perturbation enhancement training strategy and a size-segmented encoder were introduced to achieve high-precision identification of real experimental data and recognition of unknown phases.

Benefits of technology

It enables accurate structural identification without prior information, breaks through the limitations of input conditions, has the adaptability to real experimental data and the ability to identify unknown phases, and meets the scalability requirements of large-scale databases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122135831A_ABST
    Figure CN122135831A_ABST
Patent Text Reader

Abstract

This invention discloses a method and system for retrieving crystal structures using powder X-ray diffraction (PXRD) based on contrastive learning, specifically relating to the interdisciplinary field of materials science and artificial intelligence. The proposed crystal structure retrieval model transforms the original crystal structure generation task into a structure similarity retrieval task. Through contrastive learning, it maps physically enhanced experimental spectra and ideal simulated spectra to a unified embedding space, achieving high-precision crystal structure retrieval without prior knowledge such as chemical formulas or lattice parameters. Furthermore, by introducing a multi-dimensional physical perturbation enhancement training strategy, the PXRD encoder learns crystal structure fingerprints that remain unchanged under physical perturbations, significantly improving the model's robustness to complex experimental conditions. Moreover, by designing a discrimination mechanism based on a cosine similarity confidence threshold, it achieves effective identification and labeling of crystal structures not included in the database, avoiding misjudgments.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of material science and artificial intelligence, and particularly relates to a powder X-ray diffraction crystal structure retrieval method and system based on contrast learning. BACKGROUND

[0002] Crystal materials are widely used in modern technical fields such as semiconductor electronic devices, solid-state batteries, heterogeneous catalysis, etc. Powder X-ray diffraction (PXRD) is the most widely used non-destructive structure characterization method and is also the core tool for crystal structure identification. Traditional PXRD structure analysis needs to go through multiple steps such as indexing, space group determination, structure solving, and Rietveld refinement, each of which relies on deep crystallographic professional accumulation and a large amount of manual intervention, and is difficult to meet the needs of modern high-throughput automated workflow.

[0003] With the rise of deep learning, researchers have begun to introduce machine learning into PXRD phase identification, transforming it into a multi-classification problem, and using models such as convolutional neural networks to directly predict the phase category from the diffraction pattern. However, this type of solution has a fundamental flaw: the classification output is limited to the pre-set phase set during training, and when encountering unknown phases outside the training set, it cannot make correct judgments and cannot provide any warning. In addition, as the size of the material database continues to expand, the number of categories to be distinguished increases dramatically, and the training overhead and memory requirements of the model also rise, making it difficult to be practical in high-throughput scenarios.

[0004] To further improve the automation level, in recent years, deep learning methods have emerged that are based on flow matching or diffusion models and directly generate crystal structures from diffraction patterns. However, these methods at least require the known exact chemical formula to run, and most also need to provide lattice parameters or space group information to constrain the generation process. Even if the above stringent conditions are met, the Top-1 accuracy of the current best method is only 75.32%. The more fundamental limitation is that these methods are based on ideal PXRD patterns and have no solution to the complex physical disturbances such as instrument broadening, background noise, nanocrystal peak broadening, and peak shift that are commonly present in experimental measurements.

[0005] In summary, there are three core problems in the current PXRD crystal structure identification field that need to be solved: first, strong dependence on prior knowledge - chemical formula, lattice parameters, etc. Conditions are often not pre-acquired in high-throughput screening scenarios; second, vulnerability to experimental physical disturbances - models trained on ideal patterns perform significantly worse when faced with real experimental data; third, lack of out-of-distribution detection capability - unable to identify unknown phases that are not included in the database, there is a risk of misjudging unknown phases as known structures. SUMMARY

[0006] To address the aforementioned problems, the present invention aims to provide a powder X-ray diffraction crystal structure retrieval method and system based on contrastive learning, achieving high-precision retrieval across the entire nanocrystal size range.

[0007] The first aspect discloses a method for retrieving crystal structures based on contrastive learning using powder X-ray diffraction (PXRD). The method includes: constructing a crystal embedding library, wherein the crystal embedding library contains structure embedding vectors of various crystal PXRD spectra; inputting the PXRD spectra of the crystal to be retrieved into a corresponding PXRD encoder according to the grain size of the crystal to be retrieved to obtain the structure embedding vector of the crystal to be retrieved, wherein different grain sizes correspond to different PXRD encoders; and performing a search in the crystal embedding library using a cosine similarity algorithm based on the structure embedding vector of the crystal to be retrieved. When a candidate crystal structure with the highest cosine similarity greater than or equal to a preset confidence threshold is found, the candidate crystal structure with the highest cosine similarity is returned as the identification result, wherein the preset confidence threshold is used to represent the reliability of the search result.

[0008] The second aspect discloses a powder X-ray diffraction crystal structure retrieval system based on contrastive learning, characterized in that the system comprises:

[0009] A crystal embedding library construction module is used to construct a crystal embedding library, which contains structural embedding vectors of various crystal PXRD spectra. A structural embedding vector generation module is used to input the PXRD spectra of the crystal to be retrieved into the corresponding PXRD encoder according to the grain size of the crystal to obtain the structural embedding vector of the crystal to be retrieved. Different grain sizes correspond to different PXRD encoders. A retrieval module is used to search the crystal embedding library using a cosine similarity algorithm based on the structural embedding vector of the crystal to be retrieved. When a candidate crystal structure with the highest cosine similarity greater than or equal to a preset confidence threshold is found, the candidate crystal structure with the highest cosine similarity is returned as the identification result. The preset confidence threshold is used to represent the reliability of the retrieval result.

[0010] As can be seen from the above technical solutions, the present invention has the following beneficial effects:

[0011] This invention organically combines contrastive learning with multidimensional physical perturbation enhancement to construct a similarity retrieval framework for large-scale crystal structure databases. It enables accurate structure identification based solely on an experimental PXRD pattern, without requiring any prior crystallographic information such as chemical formulas, lattice parameters, or space groups. This overcomes the stringent input limitations of existing deep learning methods, providing an unprecedented practical technical means for high-throughput automated material characterization workflows. Secondly, by introducing various physical perturbation enhancement training strategies, including instrument broadening, background noise, nanocrystal peak broadening, global and local peak shifts, and microstrain broadening, this invention enables the PXRD encoder to learn crystal structure fingerprints invariant to complex physical effects commonly found in real experiments. This overcomes the limitation of existing methods, which only work effectively on ideal simulated patterns and experience significant performance degradation with experimental data, achieving direct transfer from simulated data to real experimental data. Furthermore, this invention introduces a discrimination mechanism based on a cosine similarity confidence threshold, endowing the system with the ability to distinguish data. The ability to actively identify known structures within the database and unknown phases outside the database fundamentally solves the inherent flaw of existing classification methods that can only force classification and cannot provide any warnings when encountering unknown phases outside the training set. This provides a reliable technical guarantee for automatically discovering unknown new phases in high-throughput screening. Furthermore, this invention addresses the characteristic that the diffraction peak broadening of nanocrystalline materials varies greatly with grain size by introducing a dedicated encoder trained in size segments and an online adaptive routing mechanism. This enables the system to maintain stable retrieval performance across the entire nanocrystalline grain size range of 1 to 500 nanometers, filling the gap in existing methods for handling nanocrystalline diffraction data. Finally, this invention adopts a retrieval paradigm that separates offline construction of the structure embedding library from online phase query. The encoder can be trained once and reused for a long time. When the database is expanded, only the corresponding structure embedding vector needs to be added for the newly added structures, without retraining. This fundamentally solves the engineering problem of the rapid expansion of training overhead in traditional classification methods as the number of phase categories increases, providing good engineering scalability to adapt to the continuously growing material structure database. Attached Figure Description

[0012] Figure 1 The flowchart of a powder X-ray diffraction crystal structure retrieval method based on contrastive learning provided by the present invention is shown.

[0013] Figure 2 This is a schematic diagram of the architecture of a powder X-ray diffraction crystal structure retrieval system based on contrastive learning provided by the present invention. Detailed Implementation

[0014] To make the objectives, features, and advantages of the present invention more apparent and understandable, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Several embodiments of the present invention are shown in the drawings. However, the present invention can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided so that the disclosure of the present invention will be thorough and complete.

[0015] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a particular order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in a sequence other than that illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0016] It should be noted that when an element is referred to as being "fixed to" another element, it can be directly on the other element or there may be an intervening element. When an element is considered to be "connected to" another element, it can be directly connected to the other element or there may be an intervening element. The terms "vertical," "horizontal," "left," "right," "up," "down," and similar expressions used herein are for illustrative purposes only and are not intended to indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be construed as limiting the invention.

[0017] In this invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," "linking," "fixing," etc., should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal communication between two components. Those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances. The term "and / or" as used herein includes any and all combinations of one or more of the related listed items.

[0018] In one embodiment, the present invention provides a powder X-ray diffraction crystal structure retrieval method based on contrastive learning, such as... Figure 1 As shown, the specific steps include:

[0019] S101. Construct a crystal embedding library, wherein the crystal embedding library contains structural embedding vectors of various crystal PXRD spectra;

[0020] First, a retrieval library needs to be built before constructing the crystal embedding library. The retrieval library includes ideal PXRD spectra of various crystal structures, which facilitates the training of the PXRD encoder.

[0021] Specifically, the construction of the search library uses a candidate crystal structure database as input and calls a PXRD simulation tool to generate ideal PXRD spectra in batches. This invention addresses the characteristic that the diffraction peak broadening of nanocrystalline materials varies significantly with grain size. It performs broadening processing for different nanoscale effects, applying the same target grain size-corresponding nanocrystal broadening to both the search library and the PXRD spectra of the crystal to be searched, ensuring consistency in the nanocrystal broadening dimension. This constructs a crystal structure search library covering the 1-500 nm range. This step is a one-time offline operation; when a new crystal structure is added to the search library, only the corresponding PXRD spectra need to be incrementally supplemented.

[0022] In one embodiment, the process of constructing the retrieval gallery includes:

[0023] For each crystal structure in the training set, XRDCalculator was used on a copper target. The diffraction peak positions and relative intensities are calculated within the preset 2θ scanning range to obtain the initial spectrum.

[0024] The initial spectrum's horizontal axis is converted from 2θ to the momentum transfer Q value, and the uniform sampling points are discretized into a continuous spectrum in Q space to obtain the ideal PXRD spectrum for each crystal structure in the training set.

[0025] Specifically, based on the MP-20 public dataset, which contains 45,231 inorganic crystal structures, it was divided into a training set (40,708 structures) and an unknown phase dataset (4,523 structures) in a 9:1 ratio. For each crystal structure in the training set, the XRDCalculator module of pymatgen was used on a copper target. Under the conditions of radiation (λ=1.5406Å) and a preset 2θ scanning range of 10° to 90°, the diffraction peak positions and relative intensities of the samples were calculated. Then, the horizontal axis of the spectrum was converted from 2θ to the momentum transfer Q value, where... The diffraction pattern is discretized into a continuous spectrum using 4096 uniformly sampled points in Q-space. That is, the discrete diffraction points are broadened by peak shaping and fitted into a continuous simulated spectrum. Finally, the peak intensity is normalized to the [0,1] interval to form a search library.

[0026] In one embodiment, the training process of the PXRD encoder includes:

[0027] Construct training positive and negative sample pairs, wherein the positive samples consist of ideal PXRD spectra sampled in batches from the search library and PXRD spectra after randomly applying multi-dimensional physical perturbations to the same crystal structure, and the negative samples are PXRD spectra after randomly applying multi-dimensional physical perturbations and corresponding to different crystal structures than the ideal PXRD spectra. The search library includes ideal PXRD spectra of various crystal structures.

[0028] Before the encoder is trained, a training set needs to be constructed. The training set includes positive and negative sample pairs. The positive samples are composed of ideal PXRD spectra sampled in batches from the search library and PXRD spectra after random multi-dimensional physical perturbation is applied to the same crystal structure. The negative samples are PXRD spectra after random multi-dimensional physical perturbation and the corresponding crystal structure is not the same as the ideal PXRD spectra.

[0029] Furthermore, since the PXRD patterns retrieved from the library are ideal simulation patterns broadened only by applying Scherrer nanocrystal broadening corresponding to the target grain size, it is necessary to perform additional analysis based on the same set of diffraction peaks. Various physical perturbations are randomly applied to the space, and the synthesized continuous spectrum is converted to Q space and normalized to obtain the PXRD spectrum after random application of multi-dimensional physical perturbations.

[0030] Physical perturbations include at least one of the following: instrument peak broadening and background noise, nanocrystal peak broadening, global peak position shift, local peak position shift, and microstrain broadening. That is, various physical perturbations are applied independently and randomly and can be combined arbitrarily. The parameters of each perturbation are randomly sampled within a preset range to cover the diversity of real experimental conditions.

[0031] Among them, the instrumental peak broadening and background noise are calculated according to the Caglioti equation, as shown in the formula:

[0032] (1)

[0033] in, The full width at half height of the instrument. It is a Bragg angle. , , The instrument broadening factor was randomly sampled within the ranges of [0.001, 0.005], [-0.002, 0.002], and [0.002, 0.010], with a minimum full width at half maximum (FWHM) of 0.04°. The peak shape was calculated using the Pseudo-Voigt function, as shown in the formula:

[0034] (2)

[0035] in, For the Lorentz term, Gaussian terms, mixed weights .

[0036] The background consists of a polynomial baseline with a relative peak intensity of 0.5% to 2% and a broad amorphous scattering peak superimposed with a 10% probability. Noise includes Poisson count statistics (equivalent count intensity 10000) and Gaussian electronic noise (standard deviation of 0.2% to 0.8% of peak intensity).

[0037] The peak broadening of nanocrystals is calculated according to the Scherrer equation, as shown in the formula:

[0038] (3)

[0039] in, This is the shape factor, with a value of 0.9. Where is the X-ray wavelength, and D is the grain size, randomly selected within the range of 1 nm to 500 nm. It is a Bragg angle.

[0040] For global peak shift, Bragg's law is used to uniformly transform the peak positions of all diffraction peaks, as shown in the formula:

[0041] (4)

[0042] in, The fractional change in lattice parameters is uniformly sampled within the range of [-0.05, +0.05]. For the new Bragg angle, The Bragg angle before the change is used to simulate the systematic peak position shift caused by thermal expansion, compositional changes, etc.

[0043] For local peak position shifts, a position-dependent non-uniform shift is applied to each diffraction peak using a smooth interpolation field, as shown in the formula:

[0044] (5)

[0045] in, For interpolation weights, This represents the local strain value at the control point. Several control points are set in the space. Indicates the number of control points, each Independent sampling self-standard deviation The Gaussian distribution is used to simulate peak position fluctuations caused by local stress or compositional inhomogeneity.

[0046] For micro-strain broadening, the calculation is based on the Williamson-Hall relation, as shown in the formula:

[0047] (6)

[0048] in, To simulate the root mean square microstrain, uniform sampling was performed within the range of [0, 0.002] to simulate the angle-dependent peak broadening caused by lattice distortion.

[0049] The above three types of peak width contributions are combined into a total half-width using a sum of squares method, as shown in the formula:

[0050] (7)

[0051] in, Indicates microstrain broadening, This indicates peak broadening in nanocrystals. This indicates the peak broadening and background noise of the instrument.

[0052] The PXRD encoder is trained by minimizing the InfoNCE loss function based on the training positive and negative sample pairs. This allows the PXRD encoder to cluster various perturbation PXRD patterns of the same crystal structure in adjacent positions in the embedding space, resulting in a trained PXRD encoder.

[0053] in, The loss function is shown in the formula below:

[0054] (8)

[0055] in, It is the number of sample pairs. This is a query sample The encoded vector; Is it the same as the query sample? The corresponding encoding vector of the positive sample; Is it the same as the query sample? The encoding vector of the non-corresponding negative sample.

[0056] For temperature parameters, This is used to adjust the distribution of similarity scores.

[0057] During PXRD encoder training, ideal PXRD maps are sampled in batches from the retrieved image library. Multi-dimensional physical perturbations are randomly applied to create positive and negative sample pairs. The PXRD encoder is trained by minimizing the InfoNCE loss through contrastive learning. This allows the model to cluster various perturbation maps of the same crystal structure in adjacent positions within the embedding space, ensuring that the PXRD encoder learns crystal structure fingerprints that remain invariant to physical perturbations. After training, the encoder weights are fixed, eliminating the need for retraining during subsequent library expansion.

[0058] It should be further explained that the encoding process of the PXRD encoder includes:

[0059] Multi-granularity feature sequences of crystal structure PXRD patterns are extracted using a multi-scale parallel convolution branching module.

[0060] The multi-granularity feature sequence is position-encoded by a learnable position encoding module to obtain position-encoded features.

[0061] By progressively downsampling through multiple stages of residual learning, the location encoding features are compressed to a preset dimension length. Each stage includes two residual modules with channel attention connected in series. The residual modules with channel attention are connected to the compression and activation (SE) module to realize the channel attention mechanism and adaptively adjust the channel weights.

[0062] The crystal structure embedding vector is then obtained through a normalization process.

[0063] For powder X-ray diffraction (PXRD) data, the PXRD encoder employs a one-dimensional residual convolutional neural network, primarily composed of three functional modules: a multi-scale parallel convolution module, a learnable position encoding module, and a residual module with channel attention. The overall process begins with the input data, proceeds through multi-scale feature extraction, position encoding, multi-stage residual learning, global pooling, projection head, and normalization, ultimately outputting a fixed-dimensional feature vector.

[0064] Specifically, the input data is PXRD pattern data of a crystal structure with a length dimension of 4096. Multi-scale feature extraction is achieved through a multi-scale parallel convolution module. This module sets parallel convolution branches with kernel sizes of 3, 7, 15, and 31, and extracts multi-granular features of the PXRD pattern. It can capture the fine structure of the sharp Bragg peaks without missing the low-frequency information in the broadened diffuse scattering. The outputs of each branch are spliced ​​and fused through channels, expanding the number of channels to 64 while keeping the length dimension unchanged, resulting in a 4096-dimensional multi-granular pattern feature sequence.

[0065] Furthermore, the learnable positional encoding module adds learnable positional information to the multi-granularity spectral feature sequence, preserving the sequential characteristics of the data to obtain feature encoding, while maintaining the number of channels and length dimension. Specifically, this module assigns trainable weights to each Q-value position, allowing the encoder to automatically focus more attention on diffraction peak regions with high information density during the learning process.

[0066] Next, the feature encoding obtained by the learnable location encoding module is subjected to multiple stages of residual learning. Each stage includes two residual modules with channel attention connected in series. In one specific embodiment, there are four residual learning stages. Through the four residual learning stages, the length is gradually downsampled from 4096 to 512 in feature dimension, while the number of channels is expanded from 64 to 512, thereby achieving efficient feature aggregation.

[0067] Furthermore, the residual module with channel attention introduces Squeeze-and-Excitation (SE) attention on top of the standard residual connection. Importance weights for each channel are generated through global average pooling and channel compression-excitation operations, adaptively suppressing noise-dominant channels and enhancing the response of crystal structure-related features. The processing of the residual module with channel attention specifically includes:

[0068] First, a combination of "Conv1D convolution + BatchNorm normalization + ReLU activation + Dropout regularization" from deep learning is used. Conv1D is a 1D convolutional layer used to extract sequence features (e.g., processing 1D X-ray diffraction data); BatchNorm: batch normalization, accelerating training and mitigating gradient vanishing; ReLU: activation function, introducing non-linearity to allow the model to fit complex patterns; Dropout: randomly deactivates some neurons to prevent overfitting. Then, a second layer of Conv1D + BatchNorm is passed through a compression and activation (SE) module to implement a channel attention mechanism, adaptively adjusting channel weights. Finally, a residual connection (addition) is performed with the original input x, and the output is processed through the ReLU activation function, ensuring smooth gradient propagation and enhancing feature representation.

[0069] Finally, a standardization layer is used to obtain the crystal structure embedding vector. Specifically, the output features after multi-stage residual learning are subjected to global average pooling, averaging the features at all positions in each channel to compress the three-dimensional features into two dimensions. The projection head consists of two fully connected (FC) layers, batch normalized (BN) / ReLU activation function / Dropou layer, used for feature mapping and dimensionality reduction. An L2 normalization layer is then applied to the output feature vector to perform L2 norm normalization, making the feature vector magnitude 1, thereby mapping the 4096-dimensional PXRD intensity sequence into a 512-dimensional crystal structure fingerprint embedding vector. This invention obtains a fixed-dimensional, standardized feature vector through global pooling + projection head + L2 normalization, which can be used for subsequent similarity calculations.

[0070] After obtaining the trained PXRD encoder, the solidified PXRD encoder is called to infer the full spectrum of 40,708 crystal structures in the search library, and the output structure embedding vectors are stored, thereby completing the construction of the crystal embedding library.

[0071] Furthermore, while calculating and storing the 512-dimensional structure embedding vector corresponding to each crystal structure, the crystallographic metadata (chemical formula, elemental composition, space group, lattice parameters, and material database number, etc.) of each crystal structure is also saved for filtering and parsing during online retrieval. To meet the real-time retrieval requirements of large-scale databases, the crystal embedding library establishes a fast query channel using an approximate nearest neighbor algorithm based on maximum inner product search, significantly reducing retrieval latency while maintaining high accuracy, thus meeting the real-time online retrieval needs of large-scale crystal structure databases.

[0072] S102. Based on the grain size of the crystal to be searched, input the PXRD pattern of the crystal to be searched into the corresponding PXRD encoder to obtain the structure embedding vector of the crystal to be searched. Different grain sizes correspond to different PXRD encoders.

[0073] During the online retrieval phase, the grain size is automatically estimated based on the full width at half maximum (FWHM) information of the diffraction peaks in the PXRD pattern of the crystal to be retrieved, and the encoder corresponding to the size range is adaptively selected to perform retrieval inference, thereby maintaining stable retrieval performance across the entire nanocrystal size range.

[0074] It should be noted that during the offline training phase, independent PXRD encoders are trained for different discrete grain sizes (such as 1, 2, 5, 10, 20, 50, 100, and 500 nanometers), so that each PXRD encoder is specifically adapted to the peak shape features of the corresponding grain size. At the same time, an independent crystal embedding library can be pre-computed for each grain size.

[0075] Specifically, the PXRD pattern of the crystal to be retrieved is input into the corresponding PXRD encoder according to the grain size to obtain a 512-dimensional structure embedding vector.

[0076] S103. Based on the structure embedding vector of the crystal to be retrieved, a cosine similarity algorithm is used to search the crystal embedding library. When a candidate crystal structure with the highest cosine similarity greater than or equal to a preset confidence threshold is found, the candidate crystal structure with the highest cosine similarity is returned as the identification result. The preset confidence threshold is used to represent the reliability of the retrieval result.

[0077] In one embodiment, the method for determining the preset threshold includes:

[0078] On the validation set, samples from the crystal embedding library and samples not included in the crystal embedding library were selected respectively, and the distribution of the highest cosine similarity of the two types of samples under any retrieval mode was statistically analyzed.

[0079] Stepwise scan the candidate confidence thresholds and calculate the false negative rate of samples within the library and the false positive rate of samples not included in the library, respectively.

[0080] The highest cosine similarity that is minimized when the sum of the false negative rate of samples within the library and the false positive rate of samples not included in the library is minimized is used as the preset confidence threshold in the corresponding search mode. The preset confidence threshold is different for different search modes.

[0081] Specifically, on the validation set, samples from the database (ID samples) and samples not included in the database (OOD samples) are taken respectively. Here, the database refers to the crystal embedding library. The distribution of the highest cosine similarity of the two types of samples in each retrieval mode is statistically analyzed. Candidate thresholds are scanned step by step, and the false alarm rate of ID samples and the false alarm rate of OOD samples are calculated respectively. The similarity corresponding to the minimum sum of the two error rates is taken as the optimal confidence threshold.

[0082] In addition, since the candidate pool sizes of the three retrieval modes—global library search mode, main element filtering mode, and precise chemical system mode—are different, each mode needs to independently determine its pre-set confidence threshold.

[0083] Furthermore, when the global search mode of the image library is selected, the cosine similarity is sorted without constraints within the crystal embedding image library, and the candidate crystal structure corresponding to the highest global cosine similarity is returned.

[0084] When the main element filtering mode is selected, the main constituent elements of the crystal to be detected are determined based on the precursor of the composite. The search range is narrowed to the first crystal structure subset containing the constituent elements, and the candidate crystal structure corresponding to the highest cosine similarity in the first crystal structure subset is returned.

[0085] When the precise chemistry system mode is selected, the search scope is limited to the second subset of crystal structures that have the same elemental composition as the crystal to be detected, and the candidate crystal structure with the highest cosine similarity in the second subset of crystal structures is returned.

[0086] During the online retrieval phase, based on the prior information provided by the user, cosine similarity retrieval supports the following three modes: Global Library Search Mode, which performs an unconstrained search within the complete embedded library, ranking cosine similarity without constraints and returning a global Top-K candidate crystal structures, suitable for samples with completely unknown composition; Main Element Filtering Mode, which determines the main constituent elements based on atomic ratio thresholds, narrowing the search scope to the first subset of crystal structures containing these elements before ranking, suitable for scenarios where partial composition information is known; and Precise Chemical System Mode, which limits the search scope to the second subset of crystal structures containing the exact same set of elements as the crystal to be detected, suitable for scenarios where the complete elemental composition is known. These three modes are graded from broad to narrow, allowing users to freely choose according to experimental conditions and flexibly balance coverage and search accuracy.

[0087] This invention allows for automatic switching of the search candidate range based on prior information about the element composition provided by the user; the three modes cover all usage scenarios from completely unknown to known complete composition, achieving a flexible balance between the lack of prior information and the need for high precision.

[0088] S104. When the highest cosine similarity of the retrieved candidate crystal structure is less than the preset confidence threshold, the crystal to be retrieved is marked as an unknown crystal structure, and manual review is triggered.

[0089] The highest cosine similarity obtained in step S103 is used as the criterion, and compared with a preset confidence threshold to evaluate the reliability of the identification result. During online retrieval, if the highest cosine similarity is higher than the preset confidence threshold, the identification result is output; if it is lower than the preset confidence threshold, the sample is marked as "unknown crystal structure," triggering manual review, thereby effectively avoiding the risk of misjudgment.

[0090] In another embodiment, different grain sizes correspond to different crystal embedding libraries, and the present invention includes:

[0091] Based on the grain size of the crystal to be searched, the corresponding crystal embedding library is selected for cosine similarity retrieval.

[0092] In one embodiment, the invention further includes:

[0093] Peak width analysis was performed on the PXRD pattern of the crystal to be searched to extract the full width at half maximum (FWHM) of the main diffraction peaks.

[0094] The grain size of the crystal to be searched is estimated by substituting the full width at half maximum (FWHM) of the main diffraction peaks into the Scherrer formula.

[0095] Specifically, the system first performs peak width analysis on the PXRD pattern of the crystal to be searched, extracts the full width at half maximum (FWHM) of the main diffraction peaks, and substitutes them into the Scherrer formula to estimate the average grain size. Based on this, it automatically selects the best-matching dedicated PXRD encoder and the corresponding size-matching crystal embedding library to perform the search. This adaptive routing strategy enables the system to maintain stable search accuracy across the entire nanocrystal size range of 1 to 500 nanometers.

[0096] This invention organically combines contrastive learning with multidimensional physical perturbation enhancement to construct a similarity retrieval framework for large-scale crystal structure databases. It enables accurate structure identification based solely on an experimental PXRD pattern, without requiring any prior crystallographic information such as chemical formulas, lattice parameters, or space groups. This overcomes the stringent input limitations of existing deep learning methods, providing an unprecedented practical technical means for high-throughput automated material characterization workflows. Secondly, by introducing various physical perturbation enhancement training strategies, including instrument broadening, background noise, nanocrystal peak broadening, global and local peak shifts, and microstrain broadening, this invention enables the PXRD encoder to learn crystal structure fingerprints invariant to complex physical effects commonly found in real experiments. This overcomes the limitation of existing methods, which only work effectively on ideal simulated patterns and experience significant performance degradation with experimental data, achieving direct transfer from simulated data to real experimental data. Furthermore, this invention introduces a discrimination mechanism based on a cosine similarity confidence threshold, endowing the system with the ability to distinguish between databases. The ability to actively identify known structures within the database and unknown phases outside the database fundamentally solves the inherent flaw of existing classification methods that can only force classification and cannot provide any warnings when encountering unknown phases outside the training set. This provides a reliable technical guarantee for automatically discovering unknown new phases in high-throughput screening. Furthermore, this invention addresses the characteristic that the diffraction peak broadening of nanocrystalline materials varies greatly with grain size by introducing a dedicated encoder trained in size segments and an online adaptive routing mechanism. This enables the system to maintain stable retrieval performance across the entire nanocrystalline grain size range of 1 to 500 nanometers, filling the gap in existing methods for handling nanocrystalline diffraction data. Finally, this invention adopts a retrieval paradigm that separates offline construction of the structure embedding library from online phase query. The encoder can be trained once and reused for a long time. When the database is expanded, only the corresponding structure embedding vector needs to be added for the newly added structures, without retraining. This fundamentally solves the engineering problem of the rapid expansion of training overhead in traditional classification methods as the number of phase categories increases, providing good engineering scalability to adapt to the continuously growing material structure database.

[0097] This application also provides a retrieval system corresponding to the method embodiments described above. Since the system embodiments are basically similar to the method embodiments, the description is relatively simple. For details of the relevant technical features and their effects, please refer to the corresponding descriptions of the method embodiments provided above. This disclosure provides a powder X-ray diffraction crystal structure retrieval system based on contrastive learning, such as... Figure 2 As shown, the system includes:

[0098] A crystal embedding library construction module is used to construct a crystal embedding library, wherein the crystal embedding library contains structural embedding vectors of various crystal PXRD spectra;

[0099] The structure embedding vector generation module is used to input the PXRD pattern of the crystal to be retrieved into the corresponding PXRD encoder according to the grain size of the crystal to be retrieved to obtain the structure embedding vector of the crystal to be retrieved. Different grain sizes correspond to different PXRD encoders.

[0100] The retrieval module is used to search the crystal embedding library using a cosine similarity algorithm based on the structure embedding vector of the crystal to be retrieved. When a candidate crystal structure with the highest cosine similarity greater than or equal to a preset confidence threshold is found, the candidate crystal structure with the highest cosine similarity is returned as the identification result. The preset confidence threshold is used to represent the reliability of the retrieval result.

[0101] This application also provides an electronic device, which includes a processor and a memory. The memory stores at least one instruction or at least one program, which is loaded and executed by the processor to perform the powder X-ray diffraction crystal structure retrieval method based on contrastive learning provided in the above-described method embodiments.

[0102] Furthermore, the electronic device may participate in or include the apparatus or system provided in the embodiments of this application. The electronic device may include one or more processors (processors may include, but are not limited to, processing devices such as microprocessors (MCUs) or programmable logic devices (FPGAs), memory for storing data, and transmission devices for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a power supply, and / or a camera.

[0103] It should be noted that the aforementioned one or more processors and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits can be implemented wholly or partially as software, hardware, firmware, or any other combination. Furthermore, the data processing circuits can be a single, independent processing module, or wholly or partially integrated into any other element within a device (or mobile device). As involved in the embodiments of this application, the data processing circuit serves as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).

[0104] The memory can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the method described in the embodiments of this application. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby realizing the above-mentioned data processing method. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to electronic devices via a network. Examples of the above-mentioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0105] The transmission device is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the device's communication provider. In one example, the transmission device includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device may be a Radio Frequency (RF) module, used for wireless communication with the Internet.

[0106] The display can be, for example, a touchscreen liquid crystal display (LCD), which allows users to interact with the user interface of an electronic device (or mobile device).

[0107] This application embodiment also provides a computer storage medium storing at least one instruction or at least one program, which is loaded and executed by a processor to implement the powder X-ray diffraction crystal structure retrieval method based on contrastive learning provided in the above method embodiment.

[0108] Optionally, in this embodiment, the aforementioned computer storage medium may be located at at least one of the multiple network servers in a computer network. Optionally, in this embodiment, the aforementioned storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0109] This application also provides a computer program product or computer program, which includes computer instructions stored in a computer storage medium. The processor of an electronic device reads the computer instructions from the computer storage medium and executes the computer instructions, causing the electronic device to perform the powder X-ray diffraction crystal structure retrieval method based on contrastive learning provided in the above-described method embodiments.

[0110] It should be noted that the order of the embodiments described above is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, specific embodiments have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0111] It should be understood that the above description of the preferred embodiments is quite detailed, but it should not be considered as a limitation on the scope of protection of this invention. Those skilled in the art, under the guidance of this invention, can make substitutions or modifications without departing from the scope of protection of the claims of this invention, and all such substitutions or modifications fall within the scope of protection of this invention. The scope of protection of this invention should be determined by the appended claims.

Claims

1. A method for retrieving crystal structures using powder X-ray diffraction based on contrastive learning, characterized in that, The method includes: Construct a crystal embedding library, wherein the crystal embedding library contains structural embedding vectors of various crystal PXRD spectra; Based on the grain size of the crystal to be searched, the PXRD pattern of the crystal to be searched is input into the corresponding PXRD encoder to obtain the structure embedding vector of the crystal to be searched. Different grain sizes correspond to different PXRD encoders. Based on the structure embedding vector of the crystal to be retrieved, a cosine similarity algorithm is used to search the crystal embedding library. When a candidate crystal structure with the highest cosine similarity greater than or equal to a preset confidence threshold is found, the candidate crystal structure with the highest cosine similarity is returned as the identification result. The preset confidence threshold is used to represent the reliability of the retrieval result.

2. The method according to claim 1, characterized in that, The method further includes: When the highest cosine similarity of the retrieved candidate crystal structure is less than the preset confidence threshold, the crystal to be retrieved is marked as an unknown crystal structure, and manual review is triggered.

3. The method according to claim 2, characterized in that, The method for determining the preset threshold includes: On the validation set, samples from the crystal embedding library and samples not included in the crystal embedding library were selected respectively, and the distribution of the highest cosine similarity of the two types of samples under any retrieval mode was statistically analyzed. Stepwise scan the candidate confidence thresholds and calculate the false alarm rate of samples within the library and the false alarm rate of samples not included in the library, respectively. The highest cosine similarity that is minimized when the sum of the false negative rate of samples within the library and the false positive rate of samples not included in the library is minimized is used as the preset confidence threshold in the corresponding search mode. The preset confidence threshold is different for different search modes.

4. The method according to claim 3, characterized in that, The retrieval modes include a global image library search mode, a precise chemical system mode, and a major element filtering mode. The method further includes: When the global search mode of the library is selected, the cosine similarity is sorted without constraints within the crystal embedding library, and the candidate crystal structure corresponding to the highest global cosine similarity is returned. When the main element filtering mode is selected, the main constituent elements of the crystal to be detected are determined based on the precursor of the composite. The search range is narrowed to the first crystal structure subset containing the constituent elements, and the candidate crystal structure corresponding to the highest cosine similarity in the first crystal structure subset is returned. When the precise chemistry system mode is selected, the search scope is limited to the second subset of crystal structures that have the same elemental composition as the crystal to be detected, and the candidate crystal structure with the highest cosine similarity in the second subset of crystal structures is returned.

5. The method according to claim 1, characterized in that, The training process of the PXRD encoder includes: Construct training positive and negative sample pairs, wherein the positive samples consist of ideal PXRD spectra sampled in batches from the search library and PXRD spectra after randomly applying multi-dimensional physical perturbations to the same crystal structure, and the negative samples are PXRD spectra after randomly applying multi-dimensional physical perturbations and corresponding to different crystal structures than the ideal PXRD spectra. The search library includes ideal PXRD spectra of various crystal structures. The PXRD encoder is trained by minimizing the InfoNCE loss function based on the training positive and negative sample pairs. This allows the PXRD encoder to cluster the PXRD patterns of various physical perturbations of the same crystal structure in adjacent positions in the embedding space, resulting in a trained PXRD encoder.

6. The method according to claim 5, characterized in that, The process of constructing the retrieval image library includes: For each crystal structure in the training set, XRDCalculator was used on a copper target. The diffraction peak positions and relative intensities are calculated within the preset 2θ scanning range to obtain the initial spectrum. The initial spectrum's horizontal axis is converted from 2θ to the momentum transfer Q value, and the uniform sampling points are discretized into a continuous spectrum in Q space to obtain the ideal PXRD spectrum for each crystal structure in the training set.

7. The method according to claim 5, characterized in that, The encoding process of the PXRD encoder includes: Multi-granularity feature sequences of crystal structure PXRD patterns are extracted using a multi-scale parallel convolution branching module. The multi-granularity feature sequence is position-encoded by a learnable position encoding module to obtain position-encoded features. By progressively downsampling through multiple stages of residual learning, the positional encoding features are compressed to a preset dimension length. Each stage includes two residual modules with channel attention connected in series. The residual modules with channel attention are connected to the compression and activation module to realize the channel attention mechanism and adaptively adjust the channel weights. Then, through a normalization process, the crystal structure embedding vector is obtained.

8. The method according to claim 1, characterized in that, Different grain sizes correspond to different crystal embedding libraries, and the method includes: Based on the grain size of the crystal to be searched, the corresponding crystal embedding library is selected for cosine similarity retrieval.

9. The method according to claim 8, characterized in that, The method further includes: Peak width analysis was performed on the PXRD pattern of the crystal to be searched to extract the full width at half maximum (FWHM) of the main diffraction peaks. Substitute the full width at half maximum (FWHM) of the main diffraction peaks into the Scherrer formula to estimate the grain size of the crystal to be searched.

10. A powder X-ray diffraction crystal structure retrieval system based on contrastive learning, characterized in that, The system includes: A crystal embedding library construction module is used to construct a crystal embedding library, wherein the crystal embedding library contains structural embedding vectors of various crystal PXRD spectra; The structure embedding vector generation module is used to input the PXRD pattern of the crystal to be retrieved into the corresponding PXRD encoder according to the grain size of the crystal to be retrieved to obtain the structure embedding vector of the crystal to be retrieved. Different grain sizes correspond to different PXRD encoders. The retrieval module is used to search the crystal embedding library using a cosine similarity algorithm based on the structure embedding vector of the crystal to be retrieved. When a candidate crystal structure with the highest cosine similarity greater than or equal to a preset confidence threshold is found, the candidate crystal structure with the highest cosine similarity is returned as the identification result. The preset confidence threshold is used to represent the reliability of the retrieval result.