Methods and systems for analysing organic samples

A deep learning model using a Siamese network with a contrastive learning loss effectively classifies XRPD patterns of organic compounds, addressing noise issues and improving accuracy in pharmaceutical applications.

WO2026074116A1PCT designated stage Publication Date: 2026-04-09F HOFFMANN LA ROCHE & CO AG +1
View PDF 0 Cites 2 Cited by

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Filing Date
2025-10-02
Publication Date
2026-04-09

AI Technical Summary

Technical Problem

Existing methods for analyzing X-ray powder diffraction (XRPD) patterns of organic compounds in pharmaceutical contexts are time-consuming and prone to human error due to the noisy nature of these patterns, often contaminated by solvent effects or mixed phases, requiring expert knowledge and manual inspection.

Method used

A deep learning model using a Siamese network architecture with a contrastive learning loss is trained to generate a latent space representation of XRPD spectra, enabling accurate identification of identical and non-identical organic compounds by learning an embedding space where similar inputs are closer together and dissimilar inputs are further apart.

Benefits of technology

The model achieves rapid and accurate classification of XRPD patterns for organic compounds, overcoming noise-related challenges and reducing reliance on manual inspection, with performance above baseline levels.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure EP2025078425_09042026_PF_FP_ABST
    Figure EP2025078425_09042026_PF_FP_ABST
Patent Text Reader

Abstract

Methods of characterizing a sample comprising one or more organic compounds are provided, comprising: receiving a X-ray diffraction spectrum for the sample, and inputting the X-ray diffraction spectrum for the sample into a deep learning model trained using a contrastive learning loss to produce latent space representations such that pairs of input X-ray diffraction spectra assigned a first binary label have latent space representations that are closer to each other than pairs of input X-ray diffraction spectra assigned a second binary label Related methods, products and systems are also described.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] METHODS AND SYSTEMS FOR ANALYSING ORGANIC SAMPLES

[0002] Field of the disclosure

[0003] The present invention relates to methods of characterising samples comprising organic compounds using x-ray diffraction data and particularly, although not exclusively, to methods of characterising such samples using a deep learning model trained to differentiate between X-ray diffraction spectra of samples that comprise the same compounds and samples that do not comprise the same compounds.

[0004] Background

[0005] X-ray powder diffraction (XRPD) is a fundamental analytical technique for characterizing the solid form structure of compounds. In the pharmaceutical industry, the ability to accurately compare XRPD patterns is essential for identifying polymorphs, monitoring batch consistency, and ensuring the quality of pharmaceutical products. Same materials can present non-systematic differences in diffraction patterns (Harris & Cheung, 2004). Traditional methods for comparing XRPD patterns often require expert knowledge, manual inspection and basic statistical techniques, resulting in a process that is timeconsuming and prone to human error. Recent advancements in machine learning, particularly deep learning, have shown great promise in automating complex, experience-driven processes. Convolutional neural networks (CNNs) have been successfully applied to image recognition, natural language processing, and other fields, demonstrating their ability to learn hierarchical features from raw data. Siamese networks, a specific type of neural network architecture, have been particularly effective in tasks involving similarity detection, such as signature verification and face recognition. Since the fundamental task in XRPD analyses involves determining a sample’s composition based on the comparison with known patterns, similarity detection schemes have been used in the past to tackle this class of problems, including previous applications of Siamese networks to the classification of XRPD patterns of inorganic materials (Schuetzke et al. 2020).

[0006] However, there remains a need for approaches that can be used to analyse XRPD data for organic compounds, such as in the context of pharmaceutical drug development.

[0007] Summary of the disclosure

[0008] In this work, the inventors introduce a new class of automated classifiers designed to compare XRPD measurements of organic materials using a Siamese network architecture, trained on a large, curated database of pharmaceutical organic solids. Unlike inorganic compounds, patterns of organic molecules are oftentimes noisier due to, for example, the presence of contaminants in the sample, solvent effects or the presence of mixed phases. Examples for typical patterns are depicted in Fig. 3. To tackle these challenges, the inventors used the core idea behind Siamese networks and try to learn a meaningful embedding space where similar inputs are close together, and dissimilar inputs are further apart. By leveraging this architecture, the proposed models generate a distance score that indicates the similarity between two XRPD patterns, enabling rapid and accurate identification of identical forms. The inventors proposed two different architectures comprising convolutional layers and trained using a contrastive learning loss to learn an embedding space such that two patterns representing the same phase of the same compound have embeddings that are closer together than those of two patterns representing two different phases.

[0009] Thus, according to a first aspect, there is provided a computer implemented method of characterizing a sample comprising one or more organic compounds, the method comprising: (i) receiving a X-ray diffraction spectrum for the sample; (ii) inputting the X-ray diffraction spectrum for the sample into a deep learning model that has been trained to take as input an X-ray diffraction spectrum and produce as output a latent space representation for the input X-ray diffraction spectrum, thereby obtaining a latent space representation for the X-ray diffraction spectrum for the sample, wherein the deep learning model has been trained using a contrastive learning loss to produce latent space representations such that pairs of input X- ray diffraction spectra assigned a first binary label have latent space representations that are closer to each other than pairs of input X-ray diffraction spectra assigned a second binary label; (iii) inputting a reference X-ray diffraction spectrum associated with one or more organic compounds and / or one or more phases of one or more organic compounds into the deep learning model, thereby obtaining a latent space representation for the reference X-ray diffraction spectrum; and (iv) determining, using a distance between the latent space representation of the reference X-ray diffraction spectrum and the latent space representation of the X-ray diffraction spectrum for the sample, whether the sample comprises the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum.

[0010] The contrastive learning loss may be a loss function that is based on, for each of one or more pairs of latent representations, a distance metrics between the two latent representations, and a label indicating whether the latent representations are considered to be in a negative class associated with the second binary label or a positive class associated with the first binary label. The contrastive learning loss may be a loss function that is based on, for each of a plurality of pairs of latent representations, a distance metrics between the two latent representations, and a label indicating whether the latent representations are considered to be in a negative class associated with the second binary label or a positive class associated with the first binary label, wherein the plurality of pairs of latent representations comprise one or more pairs of latent representations in the positive class and for each of one or more of the pairs of latent representations in the positive class, a respective plurality of pairs of latent representation in the negative class comprising one of the latent representations in the respective pair of latent representations in the positive class. The contrastive learning loss may be a loss function that sums over loss terms that are each evaluated for a single pair of all possible pair in a training batch, optionally a contrastive loss function as defined in eq. 1 or eq. 2, or a loss function that is based on the distances between all pairs in a set of representations comprising one or more positive pairs and a plurality of negative pairs for each positive pair, optionally a normalised temperature-scaled cross entropy loss as defined in eq. 3 or eq. 9, a N+1 tuplet loss as defined in eq. 4 or eq. 5, a softmax loss as defined in eq. 6, or a sigLIP loss as defined in eq. 7 or eq. 8. The contrastive learning loss used to train the deep learning model may be calculated or may have been calculated during the previous training of the model as: where zi and Z2 are latent space representations for two input X-ray diffraction spectra in a set of n pairs of input X-ray diffraction spectra over which the loss is evaluated, d(zi, Z2) is a distance between zi and Z2, t=exp(t’) where t’ is a learnable temperature parameter, b is a learnable bias parameter, and labels is a binary label that is 1 for pairs of X-ray diffraction spectra in the positive class and -1 for pairs of X-ray diffraction spectra in the negative class.

[0011] The contrastive learning loss used to train the deep learning model may be calculated or may have been calculated during the previous training of the model as a sum over all pairs in the positive class in a set of n pairs of input X-ray diffraction spectra over which the loss is evaluated of: logS(2n'e|x / «pi(|dex(Zpi' (Zdi)( / ZTi,)z -k) / T) )7(Eq. 9) where Zi and Zi are latent space representations for two input X-ray diffraction spectra in the positive class, Zi and Zk where k i are latent space representations for two input X-ray diffraction spectra in the negative class, d(zi, Zk) is a distance between Zi and Zk, d(zi, Zi) is a distance between Zi and Zi, T is a learnable temperature parameter, and is an indicator function evaluating to 1 if k i , and 0 otherwise. The contrastive learning loss used to train the deep learning model may be calculated or may have been calculated during the previous training of the model as a sum over all pairs in a set of n pairs of input X-ray diffraction spectra over which the loss is evaluated (e.g. a batch of training pairs) of: where Xi and X2 are latent space representations for two input X-ray diffraction spectra, dxi,x2 is a distance between Xi and X2, m>0 is a margin parameter defining the minimal distance two latent space representations should be apart in order to be considered a negative class associated with the first binary label, in Eq. 1 the negative class is associated with a first binary label y=0 and a positive class is associated with a second binary label y=1 , and in Eq. 2 the negative class is associated with a first binary label y=1 and a positive class is associated with a second binary label y=0. The parameter m may be or may have been specified during training as a hyperparameter. Alternatively, it may be or may have been optimised during training. In embodiments, m was optimised during training and determining, using the distance between the latent space representation of the reference X-ray diffraction spectrum and the latent space representation of the X-ray diffraction spectrum for the sample, whether the sample comprises the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum comprises comparing said distance to the optimised value of m or a value derived therefrom. I such embodiments, during the training of the model, when the distance between the latent space representation of the reference X-ray diffraction spectrum and the latent space representation of the X-ray diffraction spectrum for the sample is / was below the optimised value of m, the sample may be considered to comprise the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum. Conversely, when the distance between the latent space representation of the reference X-ray diffraction spectrum and the latent space representation of the X-ray diffraction spectrum for the sample is / was at or above the optimised value of m, the sample may be considered to comprise different compounds and / or different phases of the same compounds as those associated with the reference X-ray diffraction spectrum. The same principles may be applied when using the model to analyse a sample. More generally, when using the trained model to analyse a sample, when the distance between the latent space representation of the reference X-ray diffraction spectrum and the latent space representation of the X-ray diffraction spectrum for the sample is below a predetermined threshold, the sample may be considered to comprise the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum. Conversely, when the distance between the latent space representation of the reference X-ray diffraction spectrum and the latent space representation of the X-ray diffraction spectrum for the sample is at or above the predetermined threshold, the sample may be considered to comprises different compounds and / or different phases of the same compounds as those associated with the reference X-ray diffraction spectrum. The predetermined threshold may be chosen using a set of test X-ray diffraction spectra associated with known classifications as: (i) considered to comprise the same compounds and / or the same phases of the same compounds (positive class, second binary label) or (ii) considered to comprise different compounds and / or different phases of the same compounds (negative class, first binary label). For example, the predetermined threshold may be chosen as a threshold that optimises (i.e. maximises or minimises, depending on the metric) a metric selected from: AUROC, specificity, sensitivity, true positive rate, true negative rate, false positive rate, false negative rate, and combinations or derivatives thereof.

[0012] In embodiments, the distance is a Euclidian distance. In embodiments, the deep learning model has been trained as part of a Siamese neural network architecture. The deep learning model may be a deep neural network comprising one or more convolutional layers, optionally wherein each convolutional layer is a 1 D convolutional layer. The deep learning model may be a deep neural network comprising a plurality of convolutional layers in parallel associated with respective kernel sizes wherein at least two of the convolutional layers are associated with different kernel sizes. The deep learning model may be a deep neural network comprising a plurality of convolutional layers in parallel associated with respective kernel sizes wherein all convolutional layers are associated with a different kernel size. In embodiments, the deep learning model does not comprise any sequential convolutional layers. In embodiments, the deep neural network comprises a plurality of convolutional layers in parallel associated with kernel sizes between 8 and 128. In embodiments, the deep neural network comprises a plurality of convolutional layers in parallel associated with respective kernel sizes that are different from each other. In embodiments, the deep neural network comprises 3 or 4 convolutional layers in parallel. The outputs of the plurality of convolutional layers in parallel may be concatenated or fed to respective additional parallel layers then concatenated. In embodiments, the deep neural network further comprises one or more of: one or more fully connected layers and one or more attention layers. In embodiments, the one or more attention layers each comprise one or more multi-head attention blocks. In embodiments, the one or more attention layers are applied to the outputs of all of the respective parallel convolutional layers.

[0013] Determining, using a distance between the latent space representation of the reference X-ray diffraction spectrum and the latent space representation of the X-ray diffraction spectrum for the sample, whether the sample comprises the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum may comprises: (a) comparing said distance to a predetermined threshold, wherein when said distance is below the predetermined threshold, the sample is considered to comprise or consist of the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum, and when said distance is at or above the predetermined threshold, the sample is considered to comprise or consist of different compounds and / or different phases of the same compounds as those associated with the reference X-ray diffraction spectrum; or (b) comparing said distance to corresponding distances obtained using one or more further reference X-ray diffraction spectra, wherein the sample is considered to comprise the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum when said distance is one of a set of the one or more smallest distances amongst the distances associated with all reference X-ray diffraction spectra. In other words, distances may be calculated for a plurality of reference X-ray diffraction spectra and the reference X-ray diffraction spectra associated with the smallest distances may be indicative of the compounds / phases present in the sample. The set of reference X-ray diffraction spectra with the smallest distances may be selected as a predetermined number of reference X-ray diffraction spectra with the smallest distances (e.g. the 1 , 2, 3, 4 or 5 reference diffraction spectra with the smallest distances). The predetermined number may be selected depending on the expected number of different compounds / phases expected to be present in the sample. For example, for a sample that is expected to be a mixture of 2 phases, the top 2 X-ray diffraction spectra with the smallest distances may be selected. These may be spectra associated with single phases (also referred to herein as pure form spectra). The sample may then be identified as a mixture of those two phases. The set of reference X-ray diffraction spectra with the smallest distances may be selected as a set that is associated with distances below a predetermined threshold. The predetermined threshold may be a threshold associated with distances between latent space representations of samples that comprise the same compounds / phases but may additionally comprise other compounds / phases. For example, the predetermined threshold may be a threshold such that the distance between latent representations of (i) a X-ray spectrum for a sample comprising phases A and B, and (ii) a X-ray spectrum for a sample of phase A, is below the predetermined threshold, but the distance between latent representations of (i) a X-ray spectrum for a sample comprising phases A and B, and (iii) a X-ray spectrum for a sample of phase C, is at or above the predetermined threshold. The distances selected according to option (b) above may not meet a predetermined threshold for determining that the sample is considered to consist of the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum. In other words, in implementing option (a) above, a first predetermined threshold may be used to determine that the sample is considered to consist of the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum (when the distance is below said first predetermined threshold), or that the sample is considered to comprise different compounds and / or different phases of the same compounds as those associated with the reference X-ray diffraction spectrum (when the distance is at or above said first predetermined threshold). A second predetermined threshold (higher than the first predetermined threshold) may be used to determine that the sample is considered to comprise the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum (when the distance is below said first predetermined threshold), or that the sample is considered to consist of different compounds and / or different phases of the same compounds as those associated with the reference X-ray diffraction spectrum (when the distance is at or above said first predetermined threshold).

[0014] In embodiments, the deep learning model has been trained using training data comprising a plurality of single compound sets of X-ray diffraction spectra, each single compound set comprising multiple X-ray diffraction spectra of samples comprising the same organic compound in different concentrations and / or different solvents, wherein each of the plurality of single compound sets of X-ray diffraction spectra comprises spectra of samples comprising a different organic compound from other sets, and latent representations for pairs of spectra within a set are assigned the first binary label and latent representations for pairs of spectra in two different sets are assigned the second binary label.

[0015] In embodiments, the deep learning model has been trained using training data comprising pairs of training X-ray diffraction spectra associated, wherein each pair of training X-ray diffraction spectra is associated with either the first binary label or the second binary label, wherein pairs of training X-ray diffraction spectra considered to comprise the same compounds and / or the same phases of the same compounds are associated with the first binary label, and pairs of training X-ray diffraction spectra considered to comprise different compounds and / or different phases of the same compounds are associated with the second binary label. In embodiments, the deep learning model has been trained using training data comprising a plurality of sets of one or more X-ray diffraction spectra, each of the one or more X-ray diffraction spectra in a set associated with the same organic compound or composition, wherein the deep learning model has been trained using a cross-validation scheme in which one or more complete sets are excluded from the training set at each cross-validation fold. In embodiments, the deep learning model has been trained using all pairs of X-ray diffraction spectra in the training data. In embodiments, the deep learning model has been trained using a cross-validation scheme in which one or 2 complete sets are excluded from the training set at each cross-validation fold (leave one project out or leave two projects out cross-validation). In embodiments, the plurality of sets are each associated with a compound or composition that is different from that of the other sets (i.e. each set is associated with a unique compound or composition). In embodiments, the training data comprises X-ray diffraction spectra associated with single compounds or single phases of single compounds. In embodiments, the deep learning model that has been trained using training data comprising one or more simulated X-ray diffraction spectra. The one or more simulated X-ray diffraction spectra may be or may have been obtained by: combining a plurality of X-ray diffraction spectra associated with respective compounds, obtaining a simulated X-ray diffraction spectrum for a compound using a known crystalline structure of the compound, and / or obtaining a simulated X-ray diffraction spectrum from a measured or simulated X-ray diffraction spectrum by addition of noise to the measured or simulated X-ray diffraction spectrum.

[0016] The sample may comprise one or more pharmaceutical compounds. The X-ray diffraction spectrum may be an X-ray powder diffraction spectrum. The method may comprise repeating the step of inputting a reference X-ray diffraction spectrum into the deep learning model using one or more further reference X- ray spectra, and repeating the step of determining whether the sample comprises the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum for each of said further reference X-ray spectra. The reference X-ray spectra and further reference X-ray spectra may be part of a library of reference X-ray spectra. The method may be for determining whether the sample comprises the same compounds and / or phases of the same compounds as those associated with a reference X-ray diffraction spectrum in the library. The reference X-ray spectra and further reference X-ray spectra may be associated with respective samples. The method may be for determining whether any of the samples comprises the same compounds and / or phases of the same compounds. Each of the one or more reference X-ray spectra may be associated with one or more organic compounds and / or phases of organic compounds.

[0017] A second aspect of the present disclosure provides a method of identifying the presence of one or more polymorphs of a pharmaceutical compound in a sample, or monitoring the quality of a sample of pharmaceutical product, the method comprising: obtaining an X-ray diffraction spectrum for the sample, and characterising the sample using the method of any embodiment of the first aspect. Obtaining an X-ray diffraction spectrum for the sample may comprise receiving the X-ray diffraction spectrum from a user interface, computing device or data store. Thus, the method of the present aspect may also be fully computer implemented. Alternatively, obtaining an X-ray diffraction spectrum for the sample may comprise measuring an X-ray diffraction spectrum for the sample using an X-ray diffraction scanner.

[0018] According to a third aspect, there is provided a method of training a deep learning model for characterising a sample comprising one or more organic compounds, the method comprising: (i) receiving training data comprising a plurality of X-ray diffraction spectra; (ii) obtaining pairs of X-ray diffraction spectra assigned with a first binary label and pairs of X-ray diffraction spectra assigned with a second binary label; (iii) training a deep learning model to take as input an X-ray diffraction spectrum and produce as output a latent space representation for the input X-ray diffraction spectrum, thereby obtaining a latent space representation for the X-ray diffraction spectrum for the sample, wherein the deep learning model is trained using a contrastive learning loss to produce latent space representations such that pairs of input X-ray diffraction spectra assigned the first binary label have latent space representations that are closer to each other than pairs of input X-ray diffraction spectra assigned the second binary label. Embodiments of the present aspect may have any of the features described above in relation to the first aspect. For example, pairs of X-ray diffraction spectra assigned with the first binary label may be associated with samples considered to comprise different compounds and / or different phases of the same compound, and pairs of X-ray diffraction spectra assigned with the first binary label may be associated with samples considered to comprise the same compounds and / or the same phases of the same compounds.

[0019] According to a fourth aspect, there is provided a method comprising any of the steps of the first aspect and any of the steps of the third aspect.

[0020] According to a fifth aspect, there is provided a system including: at least one processor; and at least one non-transitory computer readable medium containing instructions that, when executed by the at least one processor, cause the at least one processor to implement any of the methods described herein. For example, the system may be configured to implement the methods of any embodiment of any of the first, second, third and / or fourth aspects. According to a sixth aspect, there is provided a non-transitory computer readable medium comprising instructions that, when executed by at least one processor, cause the at least one processor to perform any of the methods described herein. For example, the instructions may cause the at least one processor to implement the methods of any embodiment of any of the first, second, third and / or fourth aspects.

[0021] According to a seventh aspect, there is provided a computer program comprising code which, when the code is executed on a computer, causes the computer to perform any of the methods described herein. For example, the code may cause the computer to implement the methods of any embodiment of any of the first, second, third and / or fourth aspects. The invention includes the combination of the aspects and preferred features described except where such a combination is clearly impermissible or expressly avoided.

[0022] Summary of the Figures

[0023] Embodiments and experiments illustrating the principles of the invention will now be discussed with reference to the accompanying figures in which:

[0024] Figure 1 shows flow diagrams illustrating schematically methods of the disclosure.

[0025] Figure 1A is a flowchart illustrating schematically a method of analysing XRPD data according to embodiments of the disclosure.

[0026] Figure 1 B is a flowchart illustrating schematically a method of providing a trained machine learning model for analysing XRPD data according to embodiments of the disclosure.

[0027] Figure 2 illustrates schematically an embodiment of a system for implementing methods of the disclosure.

[0028] Figure 3 shows examples of three XRPD patterns for the same chemical compound. Two of the patterns belong to the same phase. Deciding which ones has so far involved manual classification by expert scientists.

[0029] Figure 4 shows PaCMAP (Pairwise Controlled Manifold Approximation, Wang et al. 2021) embeddings based on the latent vectors of a selected test set. Colour codes represent different ground truth forms.

[0030] Figure 5 shows architecture diagrams for models used in examples of the disclosure.

[0031] Figure 5A shows an architecture diagram for the SMolNet model used in the examples, with hyperparameters used therein.

[0032] Figure 5B shows an architecture diagram for the XRPDauto model used in the examples, with hyperparameters used therein.

[0033] Figure 6 illustrates schematically an example of a solid form screening project. (1) A candidate molecule is mixed in different solutions to explore its solid state landscape. Measurable crystalline residues that are formed are investigated using XRPD - creating a large number of measurements of potentially different materials (2). To identify the different forms obtained, typically a manual sorting is employed (3-1). Alternatively, according to examples of the present disclosure, previous projects’ data can be leveraged to train a model (here illustrated as SmolNet), which can be used to perform the same sorting task at higher throughput (3-2). Detailed description

[0034] Aspects and embodiments of the present invention will now be discussed with reference to the accompanying figures. Further aspects and embodiments will be apparent to those skilled in the art. All documents mentioned in this text are incorporated herein by reference.

[0035] The present disclosure provides new methods for analysing X-ray spectral data from samples of organic compounds. Approaches for analysing such data typically require expert knowledge, manual inspection and basic statistical techniques. An approach based on convolutional neural network (CNN) based Siamese networks has been proposed for inorganic samples in Schuetzke et al. 2020. However, the author’s work was strictly limited to inorganic crystalline materials such as metals (ores). Analysing organic samples such as those typically considered in pharmaceutical contexts is significantly more difficult because X-ray diffraction patterns of these samples are significantly noisier due to the presence of contaminants, solvent effects or mixed phases. Example of typically patterns for the same chemical compounds illustrating this problem are shown on Fig. 3. Therefore, there was no a priory expectation, prior to the inventors present work, that such machine learning approaches could work effectively to distinguish XRD patterns for the same vs different chemical compounds in view of such higher levels of noise (i.e. it was believed that expert input would be needed for such assessments). The inventors successfully demonstrated that a deep learning classifier based on the Siamese network architecture trained with a contrastive learning loss was able to perform classification of identical vs non identical XRPD measurements for organic compounds, with accuracy well above baseline. They further showed that this very success approach could be additionally enhanced with further optional features described herein including the use of parallel CNN layers, the use of a pairwise contrastive learning loss with a margin parameter trained at the same time as training the weights of the model, or a contrastive learning loss based on multiple negative pairs, and the use of training data organised as sets of spectra for the same molecule in combination with a cross- validation training scheme that exploits this structure.

[0036] In describing the present invention, the following terms will be employed, and are intended to be defined as indicated below.

[0037] An Xray diffraction (XRD) spectrum (also referred to as “X-ray diffraction pattern”) refers to a spectrum that has been obtained by measuring X-ray signal (counts or intensity) as a function of the emergent angle 20 between incident rays from an emitter and diffracted rays detected at a detector. This may be referred to as a Bragg-Brentano focussing geometry. XRD may be applied to a solid sample in the form of a powder, in which case the XRD may be referred to as X-ray Powder diffraction (XRPD). An XRD spectrum may comprise counts (intensities) for each of a plurality of angles (20). The plurality of angles, i.e. both the range and measurement density within the range may vary, e.g. depending on the configuration of the instrument with which XRD spectra are acquired. Examples of the present disclosure show the training and deployment of a deep learning model using XRD patterns including 1950 points covering a scattering angle of 20 e [3, 42). However other ranges and measurement densities may be used. The same range and measurement densities used in the training data with which a deep learning model as described herein was trained is typically expected for XRD spectra to be analysed using the trained deep learning model. However, data of corresponding range and measurement densities can be obtained by downsampling, upsampling and / or interpolation as required depending on the input XRD spectra available for a sample to be analysed.

[0038] A “sample” as used herein refers to any sample comprising one or more organic compounds that can be analysed using XRD. The sample is typically in a solid form. Thus, an organic compound or composition as described herein may be analysed in a solid state. The sample may have been crushed prior to analysis by XRD into a powder. The sample may be a sample comprising one or more crystalline phases of a single compound (i.e. polymorphs of a compound), or one or more crystalline phases of a plurality of compounds. The one or more compounds are organic compounds. This is by contrast with e.g. metallic compounds, such as pure metals, alloys, ores, metal salts, metal oxides, etc. An organic compound may be a small molecule. A small molecule may be a compound with a molecular weight below 1000 Da. An organic compound may be a drug. The terms “drug” and “pharmaceutical” or “pharmaceutical compound” are used interchangeably to refer to bioactive substances. The one or more compounds may be compounds included in a pharmaceutical preparation, including but not limited to e.g. a pharmaceutical compound (also referred to herein as active compound, active molecule or drug), an excipient, etc. The one or more compounds may be one or more drugs in development. The sample may be a sample of a drug in development, or a sample of a drug in a production process. For example, the methods described herein may be used in the context of identifying polymorphs of a compound and / or impurities while characterising the compound in pharmaceutical development, or in production (e.g. for monitoring batch consistency and ensuring quality of a product). An organic compound refers to any organic molecule or assembly. A sample may comprise one or more inorganic compounds in addition to one or more organic compounds. Thus, the terms “organic sample” and “organic composition” refers to samples and compositions that comprise at least one organic compound. In the context of the present disclosure, a sample comprising a plurality of organic compounds or a plurality of phases of one or more organic compounds may also be referred to as a composition. A pharmaceutical compound may also be referred to as an active molecule, active compound or drug. The term “composition” encompasses a sample that comprises a plurality of organic compounds to be analysed by X-ray crystallography. For the avoidance of doubt, a sample comprising a single organic compound to be analysed by x-ray crystallography in a solvent can also be referred to as a composition, whether the solvent is organic or not.

[0039] A deep learning model is a machine learning model that comprises a neural network with a plurality of layers. The deep learning models described herein are machine learning models that have been trained to produce latent space representations of input X-ray diffraction spectra such that pairs of input X-ray diffraction spectra assigned a first binary label have latent space representations that are closer to each other than pairs of input X-ray diffraction spectra assigned a second binary label. Such a machine learning model can be trained as part of a Siamese network architecture. Such a machine learning model generates latent space representations for individual input X-ray diffraction spectra, as opposed to e.g. a single representation for a pair of input spectra. The deep learning models described herein may have been trained in a supervised manner using training data comprising pairs of X-ray diffraction spectra and associated labels selected from the first binary label and the second binary label. The second binary label may be associated with pairs of X-ray diffraction spectra that are associated with samples of the same compound or composition, or samples of the same phases of the same compounds or compositions thereof. Conversely, the first binary label may be associated with pairs of X-ray diffraction spectra that are not associated with such samples (e.g. pairs of diffraction spectra for samples comprising different compounds, different phases of the same compounds, etc.). The second binary label may be 0 or 1 , and the first binary label may be 1 or 0. As the skilled person understands, either is possible as the loss function formulation used to train the deep learning model can be adapted to accommodate either configuration. Such a training may also be seen as training to classify pairs of X-ray diffraction patterns between a first class associated with the first binary label and a second class associated with the second binary label. Such a training may be described as using a Siamese network approach, since two latent representations for respective X-ray diffraction spectra of a training pair are obtained by identical copies of the same deep neural network. The deep learning model can be trained to produce such latent representations using a contrastive learning loss. A contrastive learning loss (also referred to herein simply as “contrastive loss”) is a type of objective function (also referred to as “objective function” or “loss”) that can be used for self-supervised, contrastive learning. A contrastive learning loss is a loss function that is based on a distance metric between two latent representations (also referred to as embeddings), and labels indicating whether pairs are considered to be in a negative class (first binary label) or a positive class (second binary label). A distance metric may also be referred to as a similarity metric. The distance metric may be a Euclidian distance (also referred to as L2 distance) or a cosine distance (1 -cosine similarity). As the skilled person understands, the cosine similarity between two vectors u, v is defined as sim(u, v) = (urv) / (| |u 11. ||v| |), i.e. the dot product between the vectors u and v. Note that the use of a distance metric that increases with increasing distance (e.g. Euclidian distance, (1-cosine similarity)) or decreases with increasing distance (e.g. cosine similarity) may be interchangeable with simple changing of the sign of the objective function or whether it is minimised or maximised. Loss functions are typically minimised and therefore evaluate to values that increase as distance between positive pairs increase. Some contrastive learning loss functions may also have values that increase as distances between negative pairs decrease. A contrastive learning loss may be any loss used for contrastive learning. Thus, a contrastive learning loss may also be referred to as a contrastive loss. A contrastive learning loss may be a pairwise contrastive loss. A pairwise contrastive loss is a loss function that is calculated for an individual pair of representations. This is by contrast to e.g. a triplet loss, which takes a value that is dependent on 3 representations, including an anchor representation, a representation that forms a positive pair with the anchor representation, and a representation that forms a negative pair with the anchor representation. In embodiments, a pairwise contrastive loss also includes a margin parameter m that defines the minimum distance that two latent representations should be apart from each other in order to be considered a negative class (first binary label). Such contrastive learning losses may be referred to simply as “contrastive loss”. In such embodiments, the loss may increase with the distance between latent representations assigned the second label (positive class) and with the difference between m and the distance between latent representations assigned the first label (negative class). The margin parameter is a non-negative parameter. The margin parameter may be selected as a hyperparameter of the deep learning model. Alternatively, the margin parameter may be optimised together with all other learnable parameters (e.g. network weights) of the model. A pairwise contrastive learning loss with a margin parameter (also sometimes referred to simply as “contrastive loss”, although unless context indicates otherwise the term is used herein to refer more broadly to contrastive learning losses) may be calculated as: or where Xi and X2 are latent space representations for two input X-ray diffraction spectra, dxi,x2 is a distance between Xi and X2, m>0 is a margin parameter defining the minimal distance two latent space representations should be apart in order to be considered a negative class associated with the first binary label, in Eq. 1 the negative class is associated with a first binary label y=0 and a positive class is associated with a second binary label y=1 , and in Eq. 2 the negative class is associated with a first binary label y=1 and a positive class is associated with a second binary label y=0. The distance dxi,x2 in equations (1) and (2) is a distance metric in the strict sense of the term, i.e. a value that increases as the distance between two representations increase (and the similarity between them decreases).

[0040] A contrastive learning loss may be a contrastive learning loss that is based on the distances between all pairs in a set of representations comprising one or more positive pairs and a plurality of negative pairs for each positive pair. These may be referred to as N-pair losses (where N>2) or multiple negative pairs losses. The contrastive learning loss may be a softmax, sigmoid, info normalised cross-entropy loss (infoNCE), N+1 tuplet loss, or normalised temperature-scaled cross entropy loss (NT-Xent). The contrastive learning loss may be a loss that minimises an expression depending on a term that increases with increasing distance between a positive pair representation, normalised by the sum of corresponding terms for the plurality of negative pairs for the positive pair in the set of representations. The contrastive learning loss may be a normalised temperature-scaled cross entropy loss or sigmoid loss. A normalised temperature- scaled cross entropy loss can be calculated as the sum of Eq. 3 over all positive pairs in a set of N representations: where Xi and Xi are latent space representations for two input X-ray diffraction spectra that form a positive pair in a set of N representations, sim is the similarity between Xi and Xi, r is a temperature parameter, and is an indicator function evaluating to 1 if k^i, and 0 otherwise (i.e. the denominator normalises the numerator by summing over negative pairs). An N+1 tuplet loss can be calculated as: log(l + 2 =1 exp (Xr.X; - Xr.X+)) (Eq. 4) where Xi, Xj are representations in a set of N+1 representations comprising representation Xi, a representation X+that forms a positive pair with Xi, and N-1 representations Xj that form negative pairs with Xi. A N+1 tuplet loss can also be formulated as a multiclass N-pair loss over a set of N representations that can comprise multiple positive pairs and respective plurality of negative pairs using equation (5): were Xi, Xi+are positive pairs and Xi, X where j^i are negative pairs.

[0041] Any other loss that combines the similarity between all positive pairs and the similarity between all corresponding negative pairs in a set of representations can be used. This includes the N+1 tuplet loss and NT-Xent loss above, the softmax loss used in CLIP (see Zhai et al. 2023), and other losses such as e.g. infoNCE as generally formulated in van den Oord et al. (2019). The softmax loss used in CLIP can be expressed for a unimodal model and a set comprising N positive pairs of representations as: were Xi, Xi+are positive pairs, Xi, Xj+where j^i are negative pairs, and t is a scalar parameterised as exp(t’) where t’ is a global learnable parameter. In equations 4, 5, 6, all products of representations refer to dot products (i.e. cosine similarities). However, distance metrics such as Euclidian distances can be used instead with change of signs as appropriate. The contrastive learning loss may be a loss that minimises an expression depending on a term that increases with increasing distance between any positive pair of representation in the set of representations and decreases with increasing distance between any negative pair of representations in the set of representations. For example, the contrastive learning loss may be a sigmoid loss. This can also be a loss that combines the similarity between all positive pairs and the similarity between all corresponding negative pairs in a set of representations. However, contrary to e.g. Eq. 3 or Eq. 6 above, this may not include normalisation factors that are specific to each positive pairs. This results in improved computational efficiency. For example, the sigLIP loss may be used, which can be calculated for a set comprising N pairs of representations as: where Zij is the label for a pair and is equal to 1 for a positive pair and -1 otherwise, and representations X with the same indices are positive pairs, t is a learnable temperature parameter and b is a learnable bias parameter. Note that in equation 7 the product of representations refers to the dot product (cosine similarity), but the same equation can be used with Euclidian distance using +t instead of -t, or swapping the values of the label Zij (i.e. -1 for positive pairs and +1 for negative pairs).

[0042] A contrastive learning loss function as used herein may be a pair-based contrastive loss. A pair based contrastive loss is a contrastive loss that only includes pair based terms, and does not require the formation of triplets of representations for evaluation. This may be because the loss only comprises terms that depend on the distance between representations in a single pair, or because the loss only comprises terms that depend on the distance between representations in a plurality of pairs that do not form a single triplet comprising a positive pair and a negative pair including a member of the positive pair. The deep learning model may comprise one or more convolutional layers. Such a model may be referred to as a convolutional neural network (CNN). The input to the deep learning model is typically a vector and therefore the convolutional layers may be 1 D convolutional layers. The deep learning model may additionally comprise one or more attention layers. Each attention layer may comprise a multi-head attention mechanism (Vaswani et al. 2017). The deep learning model may comprise a plurality of parallel branches, each comprising one or more convolutional layers. The convolutional layers in each branch may be associated with a kernel size, and at least two convolutional layers may have a different kernel size. For example, each of the parallel branches may comprise at least one convolutional layer with a kernel size that differs from the kernel size in the convolutional layer of the other parallel branches. Each parallel branch may further comprise one or more attention layers. Each of the parallel branches may comprise a single convolutional layer. Each of the parallel branches may comprise a convolutional layer with a kernel size that differs from the kernel size in any of the convolutional layers of the other parallel branches. For example, the deep learning model may comprise 2, 3, 4, 5 or more parallel branches each with a single 1 D convolutional layer with a different kernel size selected between 8 and 128 (e.g. 8, 16, 32, 128). The outputs of the plurality of parallel branches may be concatenated and processed by one or more further layers. The one or more further layers may comprise one or more fully connected layers. The fully connected layers may be linear. The one or more fully connected layers may be separated by and / or followed by one or more activation functions. In embodiments, the deep learning model does not comprise any sequential convolutional layers. The use of parallel convolutional layers instead of sequential convolutional layers advantageously results in a very simple architecture that has very high performance. In embodiments, the deep learning model does not comprise any attention layers. The use of a simple architecture (e.g. comprising only parallel convolutional layers and linear layers) was found by the inventors to result in excellent performance, in addition to having computational efficiency advantages compared to more complex architectures.

[0043] The deep learning model may be trained using training data comprising a plurality of pairs of X-ray diffraction spectra associated with a first binary label and a plurality of pairs of X-ray diffraction spectra associated with a second binary label. The labels associated with the training pairs may be referred to as “ground truth” labels. The training data may comprise a plurality of sets of spectra, each set comprising spectra associated with the same compound or the same phase of the same compound, and the training pairs and associated ground truth labels may be obtained by forming all possible pairs of spectra, where spectra from the same set are assigned the second binary label as ground truth label and spectra from different sets are assigned the first binary label as ground truth label. The training data may comprise at least 1000, at least 2000 or at least 3000 x-ray spectra. The plurality of sets of spectra may comprise between 1 and 100 or more spectra. Each set of spectra may comprise one or more spectra for the same compound or composition. Each set of spectra may comprise spectra from a plurality of solid forms of the same compound. In such cases, pairs of spectra from the same set but associated with different solid forms of the same compound may be associated with the first binary label (negative class). The deep learning model may be trained using a cross-validation scheme in which entire sets are included in the training and validation sets in each fold (i.e. sets are not divided between the training and validation sets in a fold). This may be referred to as a “leave one project out” or “leave two projects out” (when one, respectively two, complete sets are used for validation at each cross-validation fold) cross-validation. The plurality of sets may comprise at least 10, 11 , 12, 13, 14, 15 or 16 sets. The plurality of sets may comprise data for at least 10, 11 , 12, 13, 14, 15, 15, 17, 18, 19, 20, 21 , 22, 23 or 24 different solid forms. The training data may comprise experimentally determined XRD spectra and / or simulated XRD spectra. Simulated XRD spectra for a compound may be obtained by simulating one or more XRD spectra associated with a known crystalline structure of the compound. Simulated XRD spectra may be obtained for a composition by combining multiple simulated or experimentally determined spectra or compounds forming the composition. Simulated XRD spectra may be obtained from simulated or experimentally determined spectra by addition of noise. The training data used to train the model may comprise or consist of X-ray diffraction spectra normalised to be within a [0, 1] range. Other pre-processing methods known in the art may be used, such as e.g. smoothing using a moving average kernel. In embodiments, the training data includes raw XRPD patterns that have been normalised but not otherwise modified.

[0044] The deep learning model may be used to classify pairs of spectra (e.g. a spectrum associated with a sample and a reference spectrum) between a first class and a second class, the first class associated with the first binary label (negative class) and the second class associated with the second binary label (positive class). Pairs of spectra classified in the second class may be expected to be associated with samples of the same solid form of the same compound or the same composition (same solid forms of the same compounds). Pairs of spectra classified in the first class may be expected to be associated with samples comprising different solid forms of the same or different compounds. The methods of the present disclosure may be used to classify whether two diffraction patterns (XRD spectra) belong to the sae phase (or set of phases) or not. The classification may be associated with a predetermined threshold, such that when the distance between the latent space representations of the spectra in the pair is below the predetermined threshold, the pair is classified in the second class (positive class), and when it is at or above the predetermined threshold the pair is classified in the first class (negative class). The predetermined threshold may have been identified as part of the training of the deep learning model. For example, the predetermined threshold may be set to the value of the margin parameter m. This may be particularly advantageous when m is learned as part of the training of the model. Instead or in addition to this, the predetermined threshold may be determined using a trained model and a set of test pairs X-ray diffraction spectra associated with known classifications as: (i) considered to comprise the same compounds and / or the same phases of the same compounds (positive class, second binary label) or (ii) considered to comprise different compounds and / or different phases of the same compounds (negative class, first binary label). For example, the predetermined threshold may be chosen as a threshold that optimises a metric selected from: AUROC, specificity, sensitivity, true positive rate, true negative rate, false positive rate, false negative rate, and combinations or derivatives thereof. For example, this may be a threshold that maximises the AUROC, sensitivity or specificity, or optimally balances specificity and sensitivity according to a predetermined criterion (e.g. a predetermined threshold associated with a maximal value of the Youden’s index). As another example, the predetermined threshold may be identified based on a learned value of the margin parameter m. This can be used as an initial value for determination of a threshold to use based on a set of test X-ray diffraction spectra associated with known classifications (e.g. a set of pairs of X-ray diffraction spectra labelled by a user). The set of test pairs of X-ray diffraction spectra may be selected to include pairs that have a distance above the learned value of the margin parameter m, and pairs that have a distance below the learned value of the margin parameter m, for example within a range of distances from the learned value of the margin parameter m. A user may label each of these pairs, and the value of the predetermined threshold may be adjusted from the initial value (corresponding to the learned value of the margin parameter m) to maximise the number of test pairs that are classified in the correct class using the adjusted value as the threshold to classify the pairs.

[0045] The systems and method described herein can be implemented in a computer system, in addition to the structural components and user interactions described. As used herein, the term “computer system” includes the hardware, software and data storage devices for embodying a system and carrying out a method according to the described embodiments. For example, a computer system can comprise one or more central processing units (CPU) and / or graphics processing units (GPU), input means, output means and data storage, which can be embodied as one or more connected computing devices. Preferably the computer system has a display or comprises a computing device that has a display to provide a visual output display. The data storage can comprise RAM, disk drives, solid-state disks or other computer readable media. The computer system can comprise a plurality of computing devices connected by a network and able to communicate with each other over that network. It is explicitly envisaged that computer system can consist of or comprise a cloud computer.

[0046] As used herein, the term “computer readable storage medium” includes, without limitation, any non- transitory medium or media which can be read and accessed directly by a computer or computer system. The media can include, but are not limited to, magnetic storage media such as floppy discs, hard disc storage media, magnetic tape; optical storage media such as optical discs or CD-ROMs; electrical storage media such as memory, including RAM, ROM and flash memory; hybrids and combinations of the above such as magnetic / optical storage media.

[0047] As the skilled person understands, the complexity of the operations described herein (due at least to the amount of data that is analysed and the complexity of the machine learning models used) are such that they are beyond the reach of a mental activity. Thus, unless context indicates otherwise (e.g. where sample preparation or acquisition steps are described), all steps of the methods described herein are computer implemented.

[0048] Analysing XRD spectral data

[0049] The present disclosure provides method for analysing XRD data of organic compounds, and methods for training deep learning models to analyse XRD spectral data of organic compounds. An illustrative method of analysing spectral data of organic compounds will be described by reference to Figure 1A. An illustrative method of training a deep learning model to analyse XRD spectral data of organic compounds will be described by reference to Figure 1 B. The methods of Figures 1A and 1 B may each be performed independently, or may both be performed. For example, the steps of Figure 1 B may be performed in order to provide a trained deep learning model for use in a method of analysing XRD spectral data of organic compounds according to Figure 1A.

[0050] At step 10, XRD spectral data (i.e. a X-ray diffraction spectrum) for a sample are obtained. The sample can be a sample comprising one or more crystalline phases of a single compound, or of a plurality of compounds, as described elsewhere herein. The spectral data may be received from a user interface, a data store or a spectral data acquisition means. Alternatively, the method may comprise acquiring a XRD spectrum for a sample using an X-ray diffraction scanner.

[0051] At step 12, the X-ray diffraction spectrum for the sample is input into a deep learning (DL) model that has been trained to take as input an X-ray diffraction spectrum and produce as output a latent space representation for the input X-ray diffraction spectrum, thereby obtaining a latent space representation for the X-ray diffraction spectrum for the sample. The deep learning model has been trained using a contrastive learning loss to produce latent space representations such that pairs of input X-ray diffraction spectra assigned a first binary label have latent space representations that are closer to each other than pairs of input X-ray diffraction spectra assigned a second binary label. Methods for training such a model will be described further below by reference to Figure 1 B.

[0052] At step 14, a reference X-ray diffraction spectrum associated with one or more compounds and / or one or more phases of one or more compounds is input into the deep learning model, thereby obtaining a latent space representation for the reference X-ray diffraction spectrum. This step may be repeated for one or more further reference X-ray diffraction spectra, altogether forming a set of reference X-ray diffraction spectra (which may also be referred to as a library), The reference X-ray diffraction spectra may be experimentally measured, or simulated (including simulations of single compound / phase spectra (single form spectra) and simulations of mixtures obtained from combinations, e.g. linear combinations, of experimentally measured and / or simulated single form spectra). Note that the latent embeddings for one or more reference spectra need not be re-obtained every time a new sample is analysed, and may instead be stored for future use. Therefore, step 14 is illustrated as optional and the method may comprise instead retrieving a latent space representation previously obtained using the deep learning model for one or more reference X-ray diffraction spectra. Further, the steps of the method need not be performed in the illustrated order, and for example step 14 may have been performed at a previous time, by a different computing device and / or by a different agent from step 12.

[0053] At step 15, a distance between the latent space representation for the reference X-ray diffraction spectrum / spectra and the latent space representation for the input X-ray diffraction spectrum is calculated. The distance may be a Euclidian distance.

[0054] At step 16, it is determined, using a distance between the latent space representation of the reference X- ray diffraction spectrum and the latent space representation of the X-ray diffraction spectrum for the sample, whether the sample comprises the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum. This may comprise determining whether the sample consist of the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum (e.g. the sample is a single form sample of the same form as the reference X-ray diffraction spectrum, which is also a single form sample, or the sample is a mixture comprising the same forms as those associated with the reference X-ray diffraction spectrum). This may comprise determining whether the sample comprises the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum (e.g. the sample is a mixture that comprises a form that is the same form as the reference X-ray diffraction spectrum, which is a single form spectrum, or the sample is a mixture comprising the same forms as those associated with the reference X-ray diffraction spectrum, which is a mixture spectrum). Step 16 may comprise step 16A and / or step 16B.

[0055] At step 16A, said distance is compared to a predetermined threshold. When said distance is below the predetermined threshold, the sample can be considered to comprise or consist of the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum. When said distance is at or above the predetermined threshold, the sample can be considered to comprise or consist of different compounds and / or different phases of the same compounds as those associated with the reference X-ray diffraction spectrum. For example, a first predetermined threshold may be used to determine that the sample is considered to consist of the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum (when the distance is below said first predetermined threshold), or that the sample is considered to comprise different compounds and / or different phases of the same compounds as those associated with the reference X-ray diffraction spectrum (when the distance is at or above said first predetermined threshold). A second predetermined threshold (higher than the first predetermined threshold) may be used to determine that the sample is considered to comprise the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum (when the distance is below said first predetermined threshold), or that the sample is considered to consist of different compounds and / or different phases of the same compounds as those associated with the reference X-ray diffraction spectrum (when the distance is at or above said first predetermined threshold). Note that as the skilled person understands, reference to a sample “consisting” of one or more compounds / phases does not exclude the presence of any amounts of non-crystalline compounds, the presence of which would not have an effect on the X-ray spectra analysed.

[0056] At step 16B, said distance is compared to corresponding distances obtained using one or more further reference X-ray diffraction spectra. The sample can be considered to comprise the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum when said distance is one of a set of the one or more smallest distances amongst the distances associated with all reference X-ray diffraction spectra. In other words, distances may be calculated for a plurality of reference X-ray diffraction spectra and the reference X-ray diffraction spectra associated with the smallest distances may be indicative of the compounds / phases present in the sample. The set of reference X-ray diffraction spectra with the smallest distances may be selected as a predetermined number of reference X- ray diffraction spectra with the smallest distances (e.g. the 1 , 2, 3, 4 or 5 reference diffraction spectra with the smallest distances). The predetermined number may be selected depending on the expected number of different compounds / phases expected to be present in the sample. For example, for a sample that is expected to be a mixture of 2 phases, the top 2 X-ray diffraction spectra with the smallest distances may be selected. These may be spectra associated with single phases (also referred to herein as pure form spectra). The sample may then be identified as a mixture of those two phases. The set of reference X-ray diffraction spectra with the smallest distances may be selected as a set that is associated with distances below a predetermined threshold. The predetermined threshold may be a threshold associated with distances between latent space representations of samples that comprise the same compounds / phases but may additionally comprise other compounds / phases. For example, the predetermined threshold may be a threshold such that the distance between latent representations of (i) a X-ray spectrum for a sample comprising phases A and B, and (ii) a X-ray spectrum for a sample of phase A, is below the predetermined threshold, but the distance between latent representations of (i) a X-ray spectrum for a sample comprising phases A and B, and (iii) a X-ray spectrum for a sample of phase C, is at or above the predetermined threshold. The distances selected at step 16B may not meet a predetermined threshold for determining that the sample is considered to consist of the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum (step 16A). In other words, the distances selected at step 16B may be below a second predetermined threshold as described above but not below a first predetermined threshold.

[0057] The predetermined threshold (or second predetermined threshold) may be one that has been obtained based on a learned value of the margin parameter m of a contrastive loss used to train the deep learning model as will explained elsewhere herein.

[0058] At step 18, one or more results of the analysis may be provided to a user. This may include any of the information obtained at any of steps 12 to 16, or any information derived therefrom, such as e.g. an identification of the compounds and / or specific phases of compounds likely to be present in the sample, a ranking of reference X-ray diffraction spectra or associated compounds / phases, etc.

[0059] The deep learning model used at steps 12 and 14 may have been obtained using a method as described in relation to Figure 1 B. At step 210, training data comprising a plurality of X-ray diffraction spectra is obtained. At optional step 215, the training data may be pre-processed, such as e.g. by normalising all XRD spectra to be in the [0, 1] range. At step 220, labels are obtained for pairs of X-ray diffraction spectra formed from the training plurality of X-ray diffraction spectra, where the pairs are assigned one of a first label and a second label. At step 230, a deep learning model is trained to take as input an X-ray diffraction spectrum and produce as output a latent space representation for the input X-ray diffraction spectrum, thereby obtaining a latent space representation for the X-ray diffraction spectrum for the sample. The deep learning model is trained using a contrastive learning loss to produce latent space representations such that pairs of input X-ray diffraction spectra assigned the first binary label have latent space representations that are closer to each other than pairs of input X-ray diffraction spectra assigned the second binary label. Pairs of X-ray diffraction spectra assigned with the first binary label may be associated with samples considered to comprise different compounds and / or different phases of the same compound. Pairs of X-ray diffraction spectra assigned with the first binary label may be associated with samples considered to comprise the same compounds and / or the same phases of the same compounds. The contrastive learning loss used to train the deep learning model may be calculated as: where Xi and X2 are latent space representations for two input X-ray diffraction spectra, dxi,x2 is a distance between Xi and X2, m>0 is a margin parameter defining the minimal distance two latent space representations should be apart in order to be considered a negative class associated with the first binary label, in Eq. 1 the negative class is associated with a first binary label y=0 and a positive class is associated with a second binary label y=1 , and in Eq. 2 the negative class is associated with a first binary label y=1 and a positive class is associated with a second binary label y=0. The value of m may be specified during training as a hyperparameter. The value of m (and any other hyperparameter) may be set using prior experience or using e.g. a grid search, optionally on a smaller problem (e.g. using less training data or fewer training epochs), as known in the art. Alternatively, m may be optimised during training at the same time as all other parameters of the model (i.e. the value of m may be learned). When the value of m is learned during training, this may be used at optional step 240 as a starting point to identify a predetermined threshold to be used to classify pairs comprising a sample XRD spectrum and a reference XRD spectrum in a first class or a second class. This may be performed using pairs of spectra with known (user defined) labels as explained elsewhere herein. Step 240 may comprise identifying a first predetermined threshold and a second predetermined threshold, as described elsewhere.

[0060] The training data may comprise a plurality of sets of one or more X-ray diffraction spectra, each of the one or more X-ray diffraction spectra in a set associated with the same organic compound or composition. The training at step 230 may be performed using a cross-validation scheme in which one or more complete sets (e.g. 1 or 2 complete sets) are excluded from the training set at each cross-validation fold.

[0061] The training data obtained at step 210 may comprise one or more simulated X-ray diffraction spectra. Thus, step 210 may comprise obtaining one or more training XRD spectra from a database, computing device, user interface or memory, obtaining one or more training XRD spectra from a XRD scanner, obtaining one or more simulated XRD spectra, and combinations thereof. Simulated XRD spectra may be obtained by combining a plurality of X-ray diffraction spectra associated with respective compounds (e.g. using linear combinations), obtaining a simulated X-ray diffraction spectrum for a compound using a known crystalline structure of the compound, and / or obtaining a simulated X-ray diffraction spectrum from a measured or simulated X-ray diffraction spectrum by addition of noise to the measured or simulated X-ray diffraction spectrum. At step 250, the trained model may be provided to a user or computing device, for example for use in a method as described by reference to Fig. 1 A.

[0062] The above methods find applications in a variety of contexts. For example, the methods described herein can be used in the context of analysing a pharmaceutical compound or composition in development (e.g. polymorph screening) or in production (e.g. batch consistency check, quality control). Such a process can include analysing a XRD spectrum for a sample in comparison to a set of reference XRD spectra (e.g. spectra in a library of spectra associated with known compounds or compositions, which may include one or more synthetic spectra corresponding to simulated mixtures obtained). Such a process can instead or in addition to this include analysing a set of XRD spectra associated with respective samples, to group the samples between samples that include the same compounds or phases and those that do not.

[0063] Figure 2 shows an embodiment of a system for implementing the methods described herein. The system comprises a computing device 1 , which comprises a processor 101 and computer readable memory 102. In the embodiment shown, the computing device 1 also comprises a user interface 103, which is illustrated as a screen but may include any other means of conveying information to a user such as e.g. through audible or visual signals. The computing device 1 is communicably connected, such as e.g. through a network 6, to spectral data acquisition means and / or to one or more databases 2 storing spectral data . The one or more databases 2 may further store one or more of: training data, parameters (such as e.g. parameters of a machine learning model used herein, such as e.g. weights and / or hyperparameters of a model), simulated data, parameters and / or algorithms for simulating data, parameters and / or algorithms for preprocessing (e.g. normalising and / or smoothing data) crystalline structure data, etc. The computing device 1 may be a smartphone, tablet, personal computer or other computing device. The computing device 1 is configured to implement a method of analysing spectral data and / or a method of training a machine learning model for analysing spectral data, as described herein. In alternative embodiments, the computing device 1 is configured to communicate with a remote computing device (not shown), which is itself configured to implement a method as described herein. In such cases, the remote computing device may also be configured to send a result of such a method to the computing device. Communication between the computing device 1 and the remote computing device may be through a wired or wireless connection, and may occur over a local or public network s such as e.g. overthe public internet. The spectral data acquisition means 3 may be in wired connection with the computing device 1 , or may be able to communicate through a wireless connection, such as e.g. through WiFi and / or over the public internet, as illustrated. The connection between the computing device 1 and the spectral data acquisition means 3 may be direct or indirect (such as e.g. through a remote computer). The spectral data acquisition means 3 are configured to acquire 1 D spectral data from samples of organic molecules. The data acquisition means 3 may be an X-ray diffraction scanner.

[0064] The methods described herein can be provided as computer programs or as computer program products or computer readable media carrying a computer program which is arranged, when run on a computer, to perform the method(s) described herein.

[0065] The features disclosed in the foregoing description, or in the following claims, or in the accompanying drawings, expressed in their specific forms or in terms of a means for performing the disclosed function, or a method or process for obtaining the disclosed results, as appropriate, may, separately, or in any combination of such features, be utilised for realising the invention in diverse forms thereof.

[0066] While the invention has been described in conjunction with the exemplary embodiments described above, many equivalent modifications and variations will be apparent to those skilled in the art when given this disclosure. Accordingly, the exemplary embodiments of the invention set forth above are considered to be illustrative and not limiting. Various changes to the described embodiments may be made without departing from the spirit and scope of the invention.

[0067] For the avoidance of any doubt, any theoretical explanations provided herein are provided for the purposes of improving the understanding of a reader. The inventors do not wish to be bound by any of these theoretical explanations.

[0068] Any section headings used herein are for organizational purposes only and are not to be construed as limiting the subject matter described.

[0069] Throughout this specification, including the claims which follow, unless the context requires otherwise, the word “comprise” and “include”, and variations such as “comprises”, “comprising”, and “including” will be understood to imply the inclusion of a stated integer or step or group of integers or steps but not the exclusion of any other integer or step or group of integers or steps, “and / or” where used herein is to be taken as specific disclosure of each of the two specified features or components with or without the other. For example, “A and / or B” is to be taken as specific disclosure of each of (i) A, (ii) B and (iii) A and B, just as if each is set out individually herein.

[0070] It must be noted that, as used in the specification and the appended claims, the singular forms “a,” “an,” and “the” include plural referents unless the context clearly dictates otherwise. Ranges may be expressed herein as from “about” one particular value, and / or to “about” another particular value. When such a range is expressed, another embodiment includes from the one particular value and / or to the other particular value. Similarly, when values are expressed as approximations, by the use of the antecedent “about,” it will be understood that the particular value forms another embodiment. The term “about” in relation to a numerical value is optional and means for example + / - 10%.

[0071] The following is presented by way of example and is not to be construed as a limitation to the scope of the claims.

[0072] Examples

[0073] 1. Introduction

[0074] In fields such as materials and pharmaceutical development, the ability to rapidly and accurately identify whether two X-ray powder diffraction (XRPD) measurements are identical is crucial for efficient screening and analysis. The inventors designed novel classifiers based on a Siamese network architecture, designed to automate the comparison of XRPD patterns.

[0075] Two different architectures were tested, termed XRPDauto (embodiment 2) and SmolNet (Solid-form Molecules Network, embodiment 1) below. Both use contrastive learning losses for training the model, which comprises parallel convolutions. XRPDauto leverages a convolutional neural network (CNN) with an integrated attention mechanism to generate a robust distance score, indicating the similarity between two XRPD measurements. SmolNet does not include attention mechanisms. SmolNet was trained with multiple loss functions from the self-supervised learning domain, all yielding a substantial boost in performance compared to prior art methods with respect to class separability and precision, specifically when classifying phases of previously unseen compounds. One of these examples includes a particularly well performing model trained using a modified SigLIP loss (Zhai et al. 2023). Another one uses a vanilla contrastive loss function, but unlike traditional methods for training Siamese networks, which utilize contrastive loss functions with a fixed margin parameter, the inventors incorporate the margin as a trainable parameter within the model. During evaluation, the trained margin is directly used to convert prediction scores into binary labels.

[0076] All embodiments demonstrate significant improvements in screening efficiency across multiple active pharmaceutical ingredients, providing a powerful tool for scientists to discover and categorize measurements with reliable accuracy.

[0077] 2. Methods

[0078] Data. The dataset used in this study contains 3750 experimental XRPD patterns measured across 16 organic compounds that constitute drug candidates in a pharmaceutical research & development setting, for a total of 24 different solid forms. Each pattern constitutes a 1-d signal that contains 1950 points, covering a scattering angle of 20 e [3, 42). For each compound, patterns that belong to the same phase were manually labelled by experimentalists. All pattern intensities were normalized to be within the [0, 1] range. The inventors consider pairwise combinations of individual patterns, resulting in roughly 7 x 106pairs and a respective label specifying whether the two patterns belong to the same phase (positive class) or not (negative class). The ratio of positive to negative classes is 1 :9.5.

[0079] The dataset used in this study consists of X-ray diffraction (XRD) measurements collected from 2006 to 2024, across various research and development projects, using STOE STADI P diffractometers. These systems were equipped with curved germanium (Ge(1 11)) monochromators and Cu Ka1 radiation sources (A = 1 .54060A). The instruments operated at a voltage of 40 kV, with currents ranging from 40 mA to 50 mA, depending on the specific experimental setup. Samples weighing 1 to 5 mg were placed in sample cells with aperture diameters between 3 mm and 5 mm and a sample depth of 0.45 mm. For wet samples, Kapton film clips were used, while cellulose acetate film clips were employed for dry samples. Data were recorded in transmission mode, spanning an angular range of 3 deg to 42 deg in 20, using a moving Position Sensitive Detector (PSD) with a fixed omega angle. Over the years, two detector systems were employed for data collection. Initially, the STOE Linear Position Sensitive Detector (PSD) was used, covering up to 6 deg in 20 per scan, allowing for rapid data acquisition. A step size of 0.5 deg in 20 was applied, with dwell times ranging from 5 to 40 seconds per step, depending on the measurement mode (standard or rapid). Subsequent measurements were performed with Dectris MYTHEN K1 and MYTHEN K2 strip detectors, which offered a broader angular coverage of 12.5 deg in 20 and a high resolution of 0.01 deg in 20. For both MYTHEN detectors, the step size remained at 0.5 deg in 20, with dwell times ranging from 5 to 20 seconds per step, depending on whether standard or rapid measurements were taken.

[0080] This large curated database constitutes, to the best of the inventor’s knowledge, a first example on the feasibility of training a foundational model for organic solid diffraction patterns recognition. Model architecture. The inventors aim to classify whether two diffraction patterns X, and2belong to the same phase or not. To that end the inventors consider z = (x, 0), a function that translates individually normalized input intensities of a pattern x e IR1950to a latent embedding z e IRn, with parameters 0. For two patterns representing the same phase, the distance of their latent embeddings d(zi, Z2) should be small and vice versa.

[0081] The XRPDAuto model is trained using a Contrastive loss function, which minimizes the distance between embedding of similar patterns and maximizes the distance between embeddings of dissimilar patterns. This approach allows the models to effectively learn the underlying structure of XRPD patterns and generate a robust distance score for comparison. This approach is more computationally efficient than the use of triplet loss (as used in e.g. Schuetzke et al. 2020) since training using the contrastive loss function requires evaluating all pairs in the training data (n2tests, with n=number of observations in the training data), rather than all combinations of 3 compounds (n3tests). The inventors further also recognised that it is a more sensible choice given that the eventual purpose of the model they trained is to distinguish whether 2 patterns are from the same phase or not (i.e. a fundamentally pairwise task).

[0082] The SmolNet model (embodiment 1) is trained using one of 3 different loss functions applicable to contrastive learning tasks. This is explained in further detail below.

[0083] The architecture of embodiment 1 (SMolNet) is shown on Fig. 5A. Through hyperparameter search the inventors found that a rather simple architecture works best for this task. The model constitutes four 1- dimensional convolutional layers with a kernel size of 8 to 128, each followed by a batch normalization, Mish activation (Misra, 2019) and dropout with a probability of 0.2. All convolutional outputs are concatenated and passed on to a 64 multilayer perceptron, consisting of two dense layers with 2048 hidden neurons. The final output embedding is z e R128. When trained on the Contrastive loss, the last layer embeddings are additionally passed through a Sigmoid activation function.

[0084] The architecture of embodiment 2 (XRPDauto) is shown on Fig. 5B. This includes the following key components: (1) convolutional layers: Three parallel 1 D convolutional layers were used, with ReLU activation and max-pooling. Each convolutional layer comprised two sequential convolutions designed to extract hierarchical features from the input patterns, with a kernel size of 8 then 64, 16 then 4, and 128 then 8, respectively, a dilation of 4 to 1 and stride 16 to 1 , and dropout with a probability of 0.2; (2) attention mechanism: a self-attention layer that enhances the network’s ability to focus on the most relevant parts of the input sequences; and (3) fully connected layers: 3 fully connected layers that transform the extracted features into a compact embedding space.

[0085] An important difference in the models above is that the inventors used parallel convolution operations rather than consecutive convolution-pooling blocks (as used in e.g. Schuetzke et al. 2020). The reason behind this design choice comes from the inventors’ intuition that this would be beneficial given the multi-scale nature of the features the algorithm needs to resolve in the input data. Further, the SmolNet model does this in a strictly parallel manner, with multiple 1-dimensional convolutional layers with a kernel size of 8 to 128, whereas the XRDauto approach only covers all these resolutions with a more complex combination of parallel and sequential convolutions. Initial analyses (e.g. compare the results for XRPDauto in L2PO setting in section 3.1 below to corresponding results for SmolNet in Table 2 in section 3.2. below) showed increased model performances with parallel convolutions (and especially with the simpler fully parallel design of SmolNet), substantiating this intuition.

[0086] Training - XRPDauto. To simulate a prospective application setting as closely as possible while guaranteeing statistical significance of results, the inventors employ a nested leave-one-project-out (LOPO) cross-validation technique where at each fold the test set is selected from all measurements belonging to one chemical compound, for a total of 16 folds (see Data). A weighted sampling is employed during the training to account for class imbalance.

[0087] This model is trained on the Contrastive loss function (Hadsell et al. 2006), with the margin parameter m fixed, leading to: where dXlix2is the pairwise Euclidean distance, calculated on the latent space of the two pattern matrices X, and X2dX1,X2= || / (1, 0) - / (2, 0)||2and y is the binary labels vector for each pair in X1and X2. m > 0 is a margin parameter defining the minimal Euclidean distance two vectors should be apart in order to be considered a negative class. The value of m was optimised as a hyperparameter, and the value of m=3 was used for the results shown here. The model weights are optimized with the Adam (Kingma & Ba, 2017) optimizer at an initial learning rate of

[0088] 5 x 10-3. A validation set is selected by picking all measurements belonging to one out of the remaining 15 projects in the training data. The validation set is evaluated 20 times during one epoch and best model parameters are saved every time a new minimal loss is observed on the validation set. The learning rate is reduced by a factor of 0.1 if no improvement in the validation loss is observed after 15 evaluations. The model is trained for up to 20 epochs. Training is stopped early if no improvement in the validation loss is observed after 25 evaluations.

[0089] Training - SmolNet. The inventors train and compare the SMolNet performance after training on one of three different loss functions applicable to contrastive learning tasks. The functions tested are the Contrastive (Chopra et al. 2005, Hadsell et al. 2006), NT-XEnt / InfoNCE (Sohn 2016; van den Cord et al. 2019; Chen et al. 2020) and SigLIP (Zhai et al. 2023) losses. For training of this model, a nested leave- two-proiects-out (L2PO) cross-validation technique was employed. At each fold a unique combinations of two out of the total of 16 projects are selected with all measurements belonging to one of the two compounds used for testing, for a total of 120 fold (see Data). Patterns of the remaining 14 compounds are used for training and validation. A weighted sampling is employed during the training when using the Contrastive loss, to account for class imbalance. The model weights are optimized with the Adam (Kingma

[0090] 6 Ba, 2017) optimizer at an initial learning rate of 5 x 10-3. A validation set is selected by picking all measurements belonging to two out of the remaining 14 projects in the training data. The validation set is evaluated 20 times during one epoch and best model parameters are saved every time a new minimal loss is observed on the validation set. The learning rate is reduced by a factor of 0.1 if no improvement in the validation loss is observed after 15 evaluations. The model is trained for up to 20 epochs. Training is stopped early if no improvement in the validation loss is observed after 25 evaluations. This setup results in training times of 15-25min on a Nvidia A100 / LS40S GPU for one fold using the Contrastive loss. Significant speedup by a factor of 5-10 is achieved when training with one of the other loss functions. This is due to the explicit generation of input pairs when training with the Contrastive loss, effectively resulting in ~ N 2 data entries.

[0091] SMolNet is also trained on the contrastive loss function. Two embodiments are tested, one with a fixed margin parameter value of 8, and one with a trainable value of the margin parameter. In the latter embodiment, unlike the embodiment above and previous applications of the contrastive loss function, the inventors do not treat m as a hyperparameter, and instead optimise it as part of the model parameters, leading to: where dx,X2is the pairwise Euclidean distance, calculated on the latent space of the two pattern matrices X, and X2dX1,X2= || / (1, 0) - / (2, 0)||2and y is the binary labels vector for each pair in X1and X2. m > 0 is a margin parameter defining the minimal Euclidean distance two vectors should be apart in order to be considered a negative class. The inventors use an initial value of m = 8 and chose to optimize the value of m as part of the model parameters. The inventors are aware that this is a peculiar choice, given that at m < d the second term in the loss function becomes non-contributing. This is discussed in the Results section.

[0092] When trained using the sigLIP loss, the inventors proposed two modifications of the loss as originally described. First, rather than using a cosine similarity for training the embeddings, the Euclidean distance is used to generate the logit values. This is motivated by the improved classification performance, as shown in the results below. Second, since we are not dealing with a self-supervised task, the inventors relax the criterion that all matching pairs are only found along the diagonal of the pairwise matrix of labels. A pseudoimplementation of the modified SigLIP algorithm is provided below (text in italics preceded by a hash are comments):

[0093] # n : batch size

[0094] # emb1 : model embeddings to be compared with emb2 [n, dim] 3 # emb2 : model embeddings to be compared with emb1 [n, dim] 4 # labelsl : labels of embl [n, 1]

[0095] # Iabels2 : labels of emb2 [n, 1]

[0096] # t_prime , b : learnable temperature and bias t = exp(t_prime) z1 = I z2 = I logits labels = int(labels1 == labels2.T) # [n,n], positive pairs: 1 labels[labels==O] = -1 # negative pairs: -1 loss = -sum(log_sigmoid(labels * logits)) / n

[0097] Thus, the modified sigLIP loss is calculated as: where n is a number of pairs in a batch (batch size), t=exp(t’) where t’ is a learnable temperature parameter, b is a learnable bias parameter, d(z1 , z2) is the normalised L2 distance between the embeddings of a pair of XRPD X1 and X2, and labels are 1 for positive pairs and -1 for negative pairs.

[0098] The NT-XEnt loss was also modified to use a L2 distance instead of the cosine similarity as described in Chen et al. 2020. Thus, the modified NT-Xent loss was calculated as a sum over all pairs in the positive class in a set of n pairs of input X-ray diffraction spectra over which the loss is evaluated (batch) of: logS(2n'e|x / «pi(|dex(Zpi' (Zdi)( / zT;,)z -k) / T) )7(Eq. 9) where Zi and Zi are latent space representations for two input X-ray diffraction spectra in the positive class, Zi and Zk where k i are latent space representations for two input X-ray diffraction spectra in the negative class, d(zi, Zk) is the L2 distance between Zi and Zk, d(zi, Zi) is the L2 distance between Zi and Zi, T is a learnable temperature parameter, and is an indicator function evaluating to 1 if k i , and 0 otherwise.

[0099] Baseline model. To provide a lower bound for predictivity, the performance of the models is compared to a naive baseline model, where the score is directly computed from the Euclidean distance of the two patterns in question, such that: d(zi, Z2)=||xi-X2||. Normalised patterns were used for this (normalised to be in the [0, 1] range as was done for the training data. The inventors followed the same cross-validation procedure as above, computing all pairwise Euclidean distances on the raw 1-d input signals in the training data, interpreting the results as classified probabilities. They then choose a threshold that maximizes the F1 score and apply it to the test set patterns in order to derive predicted binary labels. Additionally, they compared the performance of SMolNet to a previously published CNN architecture (Wang et al. 2020; Schuetzke et al. 2020 - except that the published model was trained using a triplet loss and inorganic crystal XRD data, whereas the models shown here re-used the architecture but trained it on the data above, and using a Contrastive loss) and a similarity measure by de Gelder et al. 2001. Both methods were developed specifically for the classification of XRPD patterns, albeit in the context of inorganic crystalline solids.

[0100] 3. Results

[0101] Advancements in artificial intelligence have revolutionized various field by automating complex, experience- driven processes. In pharmaceutical solid-state development, similar to materials science, there is a growing need to automate the analysis of X-ray powder diffraction (XRPD) patterns, which are critical for identifying and characterizing the solid form landscape of active pharmaceutical ingredients (APIs). Here, multiple patterns from crystallization experiments of the same API are compared and assigned to a set of reference diffractograms, each representing a distinct solid form of the compound of interest, as depicted in Figure 6. Traditional methods for XRPD pattern comparison often require expert knowledge and manual inspection, making the process time-consuming and susceptible to human error. Moreover, manual interpretation becomes impractical when dealing with hundreds or thousands of samples generated from high throughput crystallization experiments aimed at discovering new solid forms.

[0102] Previous work to automate the classification of XRPD patterns includes measures operating directly on the signals, CNN classifier and Siamese networks. A key limitation in many of these works consists in framing this exercise into a classification task where the reference forms are known a priori. In practice however, a new unseen form can be observed at every measurement during experimental screening. Further, most of the research in this field focuses on highly crystalline inorganic materials that typically exhibit simpler and sharper diffraction peaks due to high symmetry and rigid crystal structures. Here the generation of synthetic XRPD patterns is a common technique for enrichment of training data. Small molecule APIs however, typically produce more complex XRPD patterns with broader peaks and additional artifacts, stemming from their intricate molecular structures, lower symmetry, and variations such as amorphous backgrounds, height preparation shifts, preferential orientation, and particle size variance. These complexities are especially evident in real-life data obtained from solid form screening routines of organic APIs. Such variations pose significant challenges for automated pattern recognition and classification as methods developed for inorganic materials may not transfer directly to the organic domain.

[0103] To address these challenges, the inventors developed a novel deep learning framework specifically designed for the pairwise classification and identification of XRPD patterns of organic crystalline materials. Their approach leverages Siamese networks to capture subtle similarities and differences between complex diffraction patterns, even with limited training data. By training directly on experimental XRPD data from organic crystals, the model bypasses the need of synthetic data augmentation and demonstrates reliable generalization to new, unseen patterns and chemical spaces. The work in these examples shows a novel application of Siamese networks, including a Siamese network architecture, trained on a modified SigLIP loss for the first time to handle organic XRPD patterns in a zero shot learning setting. The inventors further proposed a robust cross validation strategy to both train and validate ensuring no input structures are leaking from the training set, using direct training and testing on experimental data using a leave-two- compounds-out routine. The inventors further demonstrate significant improvements over non data-driven methods and previous architectures in discriminating across different forms.

[0104] 3. 1. XRPDauto (embodiment 2)

[0105] The inventors evaluated XRPDauto on a diverse dataset of XRPD measurements collected from multiple pharmaceutical projects. The results demonstrate significant improvements in screening efficiency and accuracy, with XRPDauto achieving an accuracy of 98.7%, a precision of 98.5%, a recall of 98.9%, and an F1-score of 98.7%. These finding highlight the potential of XRPDauto as a valuable tool for pharmaceutical research, enabling scientists to quickly and accurately identify identical XRPD patterns and streamline the screening process.

[0106] To showcase the broad effectiveness of this approach in a pharmaceutical development setting, the inventors follow a leave-one-project-out splitting (LOPO) strategy. The initial dataset is divided in different projects - collections of measurement belonging to the same compound - comprising of up to 3 different forms. The inventors set up a LOPO split by first training on all projects except one. As some projects do not contain necessarily more than one form, the positive class fraction can be 1 (as shown in Table 1).

[0107] Table 1 : Table showing the LOPO performance over each project and their average values across them. The F-1 scores are reported only in cases of both classes in tests.

[0108] The observed performances of the models depict a sharp true positive detection (e.g. classifying matching patterns) and a less stark - yet effective - performance in classifying negative outcomes (e.g. mismatching patterns). Note that the amount of positive labels in the training data is substantially inferior to that of the testing setting. An important detail is that redundant classification of pattern often involves confirmation of same labels, thus having a better true positive ratio (TPR) over true negative ratio (TNR) is a preferrable feature. Finally, the inventors note that while the models training data will differ between each instance - the inventors remark how the swap of a single project corresponds to a change of < 10% of the overall training data. The outcome of this challenging exercise prove a more varied outcome, providing a generally high accuracy across all the folds.

[0109] The performance of the model was also tested in a leave-two-projects out setting, with the following results (average L2PO performance and their 95% confidence intervals): AUCROC: 0.54±0.12; Acc: 0.45±0.35, F1 : 0.47±0.31 , TPR: 0.23±0.59, TNR: 0.79±0.56, margin: 3.00±00. The inventors also verified that the embedding vectors obtained by the trained XRPDauto models allow an interpretable of the diffraction patterns landscape. They showed that a non-linear embedding such as PaCMAP (Yang et al. 2021) (in Fig. 4) provides an intuitive and insightful depiction of space explored so far thus enabling fast visual identification of potentially difficult pattern assignments.

[0110] These results extensively demonstrate that the proposed approach has very good performance across different pharmaceutical materials.

[0111] 3.2. SmolNet with contrastive loss and trainable margin (embodiment 1)

[0112] Average results of the L2PO cross-validation are presented in Table 2, showing the area under the ROC curve (AUROC), accuracy, F1 score, true positive and false negative rates, and the threshold value used to convert scores to binary labels. A list of individual values per fold is provided in Table 3. These data show that a naive baseline model already performs well in separating positive from negative classes, albeit with lower accuracy in confirming matching patterns. However, the machine learning model (SMolNet) substantially outperforms the naive model in class separation, achieving an AUROC of 0.94 (approximately 10% improvement over the baseline). This is also the case for the version of the model with fixed margin, although the average accuracy of this model is lower than that of the optimised margin model (driven by low TNR).

[0113] Notably, the reported classification metrics were obtained using the optimized margin parameter directly as a threshold for the conversion of predicted scores to binary labels. The data show that this approach results in already good initial performance with respect to precision and recall, and could potentially alleviate the need for additional threshold optimization. The increased AUROC score compared to the baseline is particularly significant in typical human-in-the-loop scenarios where partial labelling is performed preliminarily on a subset of data points. This allows for rapid threshold optimization on test data (i.e. a user would manually label a few patterns to adjust the threshold from the already pre-optimised value of the automatically identified margin), making SMolNet especially valuable in real-world applications where efficiency and accuracy are paramount.

[0114] Table 2: Average L2PO performance and their 95% confidence interval for SMolNet and the naive Euclidean approaches. Showing the area under the ROC curve (AUROC), F1 score, true positive (TPR) and true negative (TNR) rates. Additionally, the average margin for the conversion of scores to classes is shown for each method. Comparative values for the XRPDauto model (fixed margin, mixture of parallel and sequential convolutional layers, more complex architecture comprising attention layers) are provided in 3.1 , underlining the benefits of the SMolNet architecture.

[0115]

[0116] Table 3: List of all performances across each project pair in the L2PO scheme 1 . The optimization of the margin parameter is unconventional. While mathematically one would expect it to vanish during optimization, the inventors’ observations indicate that it converges to positive values below the initial setting of m = 8. Interestingly, a fixed margin model appeared to perform significantly worse than their best reported models. As an additional finding, the inventors observed that more complex model architectures do not perform better than the SMolNet configuration (compare e.g. the results for XRPDauto with additional attention mechanisms to those of SMolNet).

[0117] 3.3. S mol Net with alternative contrastive learning losses (embodiment 1)

[0118] Average results of the L2CO cross-validation are presented in Table 4, showing the area under the ROC curve (AUROC), area under the precision-recall curve (AUPRC), accuracy and F1 score. Note that the AUPRC value associated with a random model is variable, equaling to the ratio of positive labels in the test set, AUPRCrandom = Npositive / Ntotal. The inventors thus report this metric as the delta above the baseline value: AUPRC = AUC(R, P ) - AUPRCrandom.

[0119] The findings in Table 4 reveal that the naive and de Gelder models already perform well in separating positive from negative classes with an above-average precision. Hard classifier metrics, i.e. Accuracy and F1 score are best for these models, hinting that threshold finding might be easiest when using simple approaches that operate directly on the input patterns. Nevertheless, machine learning approaches clearly improve on both AUROC and AUPRC metrics. This is particularly important when evaluating cases as ours, where a high class-imbalance can produce overly-optimistic accuracy and F1 scores. The inventors therefore argue that evaluating models on the soft classifier metrics is more meaningful if bias to a particular class should be avoided. The data further show improvements in all metrics when comparing the SMolNet to a previously published architecture for the classification ofXRPD spectra (note this is not the same model as disclosed in those papers, but the same architecture trained on the data presented herein and using a contrastive loss). In particular training on the NT-XEnt and SigLIP loss functions appears to be highly advantageous when high average precision and class separability are desired. The best-performing model in this data was SMolNet trained on the SigLIP loss, resulting in average AUROC and AUPRC values of 0.98 and 0.65, respectively. Although the de Gelder method produces the best F1 score, the inventors argue that the increased AU{ROC,PRC} scores of the machine learning models is particularly significant in typical human- in-the-loop scenarios where partial labelling is performed preliminarily on a subset of data points. This allows for further threshold optimization on test data, making SMolNet especially valuable in real-world applications where efficiency and accuracy are paramount.

[0120] Table 4. Average L2C0 performance and their 95% confidenc interval for various tested approaches, and parameters used. Showing the area under the ROC curve (AUROC), area under the precision- recall curve (AUPRC), Accuracy and F1 score. Bold=best model.

[0121] 4. Conclusion

[0122] The inventors have provided new model architectures and extensive proof of their performances across different pharmaceutical materials. The ability to reliably distinguish between similar and dissimilar patterns across different organic compounds and compositions constitutes a fundamental first step in the direction of tackling this problem with a foundational model approach.

[0123] The results in section 3.3. further report that the incorporation of contrastive loss functions into the model training procedure can be highly beneficial. The results in 3.2 show that class separation based on the raw scores is superior to naive approaches, and as such the inventors address the question of optimal threshold finding only briefly in this work. Aside from the fact that threshold finding is strongly affected by training procedures, the inventors observe that it will also be highly dependent on the test data and is especially challenging for the case where test compounds are not present in the training data.

[0124] Having established a reliable architecture in complex pure phase projects, the inventors postulated that the approach could be extended with the integration of measurements from various sources (e.g. mining large community databases such as CSD, www.ccdc.cam.ac.uk / solutions / software / csd / , and MP, nextgen. materialsproject.org / ), as well as synthetic data coming from crystal structure prediction simulations (see Example 2). Finally, by combining the multiple single phase data the inventors believe that the approach can be extended to tackle the challenging task of mixture determination. Specifically, assuming that the pattern of a mixture of phases is a linear combination of the patterns of the phases in the mixture, single-form training data can be used to generate patterns for mixtures, and the latent embedding of these patterns can be compared to identify the phases that are closest to a query pattern. Alternatively, latent embeddings of mixtures can be compared with latent embeddings of pure phases to identify the likely constituents of the mixture, since the distance between latent embeddings of mixtures and latent embeddings of their constituent single phases can be expected to be intermediate between the distances between embeddings of two identical phases and the distances between embeddings of two different phases.

[0125] Example 2 - Training with synthetic data

[0126] Deep learning models are optimally trained with large, high-quality datasets. However, real data is often limited. Data augmentation using supplementary synthetic data can help overcome data scarcity issues. This is especially relevant to XRPD spectra data, where datasets may be small, and / or where model training is required to be relatively specific to compound identity or class. The inventors postulated that this problem could be alleviated by using molecular crystal structures to generate synthetic XRPD spectra.

[0127] Theoretical XRPD patterns can be obtained from crystal structures using pyMatGen (pymatgen.org / ), Mercury (www.ccdc.cam.ac.uk / solutions / software / mercury / ) or the STOE software WinXPow (www.stoe.com / products / winxpow / ). These can then be used to generate experimentally realistic patterns by injecting noise and / or biases into the data (e.g. stochastically modifying the patterns based on artifacts that include background noise, strain, texture, small particle size, air scattering, and amorphous content, which are all commonly observed in real samples).

[0128] To the best of the inventors’ knowledge, the generation of synthetic XRPD spectra based on molecular crystal structures for the purpose of data augmentation has not been reported in the field of deep learning for molecular XRPDs. XRPD data augmentation has not been reported to date in the field of organic chemistry. However, it has been used in the field of inorganic chemistry and materials discovery (Schuetzke et al. 2021 ; Szymanski et al. 2023). For example, simulated data can be modified to replicate artifacts using one or more of: implementing random changes in the lattice parameters of each phase within boundaries (e.g. up to ±3%) to replicate peak shifts caused by strain, varying peak intensities randomly within boundaries (e.g. up to ±50%) according to preferred crystallographic orientation (texture) along randomly sampled Miller indices ([hkl] where 0 < h k I < 2), sampling different peak widths using the Scherrer equation based on grain sizes within predetermined ranges, adding Gaussian noise with a standard deviation of a predetermined percentage (e.g. 5%) of peak intensity (all of which are described in Szymanski et al. 2023), modelling uncertainties in the measurements by including Gaussian noise, adding an air scattering effect at low 20 angles, and adding background noise using a high-order polynomial function (Chebyshev) which is able to simulate background of different kinds including amorphous content (all of which are described in Schuetzke et al. 2021).

[0129] Further, the inventors also postulated that additional training data representing mixtures can be obtained from real and simulated spectra for single compounds. Indeed, such patterns can be mixed in arbitrary amounts by linear combinations to produce virtually unlimited mixture signals for bolstering existing experimental datasets.

[0130] References

[0131] A number of publications are cited above in order to more fully describe and disclose the invention and the state of the art to which the invention pertains. Full citations for these references are provided below. The entirety of each of these references is incorporated herein.

[0132] K. D. Harris and E. Y. Cheung, “How to determine structures when single crystals cannot be grown: Opportunities for structure determination of molecular materials using powder diffraction data,” Chemical Society Reviews, vol. 33, no. 8, pp. 526-538, 2004.

[0133] A. Vaswani et al., “Attention is all you need,” in Advances in neural information processing systems, 2017, pp. 5998-6008. J. Schuetzke, A. Benedix, R. Mikut, and M. Reischl, “Siamese networks for 1d signal identification,” in Proceedings-30. Workshop Computational Intelligence: Berlin, vol. 26, 2020, p. 27.

[0134] D. Misra, “Mish: A self regularized non-monotonic neural activation function,” CoRR, vol. abs / 1908.08681 , 2019. arXiv: 1908.08681. [Online]. Available: arxiv.org / abs / 1908.08681 .

[0135] D. P. Kingma and J. Ba, Adam: A method for stochastic optimization, 2017. arXiv: 1412.6980 [cs.LG]. [Online]. Available: arxiv.org / abs / 1412.6980.

[0136] R. Hadsell, S. Chopra, and Y. LeCun, “Dimensionality reduction by learning an invariant mapping,” in 2006 IEEE computer society conference on computer vision and pattern recognition (CVPR’06), IEEE, vol. 2, 2006, pp. 1735-1742.

[0137] Y. Wang, H. Huang, C. Rudin, and Y. Shaposhnik, “Understanding how dimension reduction tools work: An empirical approach to deciphering t-sne, umap, trimap, and pacmap for data visualization,” Journal of Machine Learning Research, vol. 22, no. 201 , pp. 1-73, 2021 . [Online].

[0138] Available:jmlr.org / papers / v22 / 20-1061 .html.

[0139] Schuetzke, Jan et al. “Enhancing deep-learning training for phase identification in powder X-ray diffractograms.” lUCrJ vol. 8, Pt 3 408-420. 1 Apr. 2021 , doi:10.1107 / S2052252521002402

[0140] Szymanski, N.J., Bartel, C.J., Zeng, Y. et al. Adaptively driven X-ray diffraction guided by machine learning for autonomous phase identification, npj Comput Mater 9, 31 (2023). doi.org / 10.1038 / s41524- 023-00984-y

[0141] R. de Gelder, R. Wehrens, and J. A. Hageman, “A generalized expression for the similarity of spectra: Application to powder diffraction pattern classification” Journal of Computational Chemistry, vol. 22, no. 3, pp. 273-289, 2001.

[0142] H. Wang et al., “Rapid identification of x-ray diffraction patterns based on very limited data by interpretable convolutional neural networks,” Journal of Chemical Information and Modeling, vol. 60, no. 4 pp. 2004-2011 , Mar. 2020, ISSN: 1549-960X. DOI: 10.1021 / acs.jcim.0c00020

[0143] Zhai X., Mustafa B., Kolesnikov A., and Beyer L. Sigmoid loss for language image pre-training, 2023. arXiv: 2303.15343. [cs.CV]

[0144] S. Chopra, R. Hadsell, and Y. LeCun, “Learning a similarity metric discriminatively, with application to face verification,” in 2005 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR’05), vol. 1 , 2005, 539-546 vol. 1. DOI: 10.1109 / CVPR.2005.202.

[0145] K. Sohn, “Improved deep metric learning with multi-class n-pair loss objective,” in Advances in Neural Information Processing Systems, D. Lee, M. Sugiyama, U. Luxburg, I. Guyon, and R. Garnett, Eds., vol.

[0146] 29, Curran Associates, Inc., 2016. [Online]. Available: proceedings. neurips.cc / paper_files / paper / 2016 / file / 6b180037abbebea991d8b1232f8a8ca9-Paper.pdf.

[0147] A. van den Oord, Y. Li, and O. Vinyals, Representation learning with contrastive predictive coding, 2019. arXiv: 1807.03748 [cs.LG]. [Online]. Available: https: / / arxiv.org / abs / 1807.03748.

[0148] T. Chen, S. Kornblith, M. Norouzi, and G. Hinton, A simple framework for contrastive learning of visual representations, 2020. arXiv: 2002.05709 [cs.LG]. [Online]. Available: https: / / arxiv.org / abs / 2002.05709.

Claims

Claims:1 . A computer-implemented method of characterizing a sample comprising one or more organic compounds, the method comprising: receiving a X-ray diffraction spectrum for the sample, inputting the X-ray diffraction spectrum for the sample into a deep learning model that has been trained to take as input an X-ray diffraction spectrum and produce as output a latent space representation for the input X-ray diffraction spectrum, thereby obtaining a latent space representation for the X-ray diffraction spectrum for the sample, wherein the deep learning model has been trained using a contrastive learning loss to produce latent space representations such that pairs of input X-ray diffraction spectra assigned a first binary label have latent space representations that are closer to each other than pairs of input X-ray diffraction spectra assigned a second binary label, inputting a reference X-ray diffraction spectrum associated with one or more organic compounds and / or one or more phases of one or more organic compounds into the deep learning model, thereby obtaining a latent space representation for the reference X-ray diffraction spectrum, and determining, using a distance between the latent space representation of the reference X-ray diffraction spectrum and the latent space representation of the X-ray diffraction spectrum for the sample, whether the sample comprises the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum.

2. The method of claim 1 , wherein the contrastive learning loss is a loss function that is based on, for each of a plurality of pairs of latent representations, a distance metrics between the two latent representations, and a label indicating whether the latent representations are considered to be in a negative class associated with the second binary label or a positive class associated with the first binary label, wherein the plurality of pairs of latent representations comprise one or more pairs of latent representations in the positive class and for each of one or more respective ones of the pairs of latent representations in the positive class, a respective plurality of pairs of latent representation in the negative class comprising one of the latent representations in the respective pair of latent representations in the positive class, optionally wherein the deep learning model has been trained using training data comprising a plurality of single compound sets of X-ray diffraction spectra, each single compound set comprising multiple X-ray diffraction spectra of samples comprising the same organic compound in different concentrations and / or different solvents, wherein each of the plurality of single compound sets of X- ray diffraction spectra comprises spectra of samples comprising a different organic compound from other sets, and latent representations for pairs of spectra within a set are assigned the first binary label and latent representations for pairs of X-ray diffraction spectra in two different sets are assigned the second binary label.

3. The method of claim 1 or claim 2, wherein the contrastive learning loss is a loss function that sums over loss terms that are each evaluated for a single pair of all possible pair in a training batch, optionally a contrastive loss function as defined in eq. 1 or eq. 2, or a loss function that is based onthe distances between all pairs in a set of representations comprising one or more positive pairs and a plurality of negative pairs for each positive pair, optionally a normalised temperature-scaled cross entropy loss as defined in eq. 3 or eq. 9, a N+1 tuplet loss as defined in eq. 4 or eq. 5, a softmax loss as defined in eq. 6, or a sigLIP loss as defined in eq. 7 or eq. 8.

4. The method of any preceding claim, wherein the first binary label is associated with a positive class and the second binary label is associated with a negative class, and the contrastive learning loss used to train the deep learning model was calculated as:where zi and Z2 are latent space representations for two input X-ray diffraction spectra in a set of n pairs of input X-ray diffraction spectra over which the loss is evaluated, d(zi, Z2) is a distance between zi and Z2, t=exp(t’) where t’ is a learnable temperature parameter, b is a learnable bias parameter, and labels is a binary label that is 1 for pairs of X-ray diffraction spectra in the positive class and -1 for pairs of X-ray diffraction spectra in the negative class;(ii) a sum over all pairs in the positive class in a set of n pairs of input X-ray diffraction spectra over which the loss is evaluated of: log (Eq. 9)where Zi and Zi are latent space representations for two input X-ray diffraction spectra in the positive class, Zi and Zk where k i are latent space representations for two input X-ray diffraction spectra in the negative class, d(zi, Zk) is a distance between Zi and Zk, d(zi, Zi) is a distance between Zi and Zi, T is a learnable temperature parameter, andis an indicator function evaluating to 1 if k i , and 0 otherwise; or(iii) a sum over all pairs in a set of n pairs of input X-ray diffraction spectra over which the loss is evaluated of:-,ydx' , ,x2+ 1 (1 - y) (max(Eq. 1) or2(1-^^+y (max(-dX1.X2, 0)2) (Eq. 2) where Xi and X2 are latent space representations for two input X-ray diffraction spectra, dxi,x2 is a distance between Xi and X2, m>0 is a margin parameter defining the minimal distance two latent space representations should be apart in order to be considered a negative class associated with the first binary label, in Eq. 1 the negative class is associated with a first binary label y=0 and a positive class is associated with a second binary label y=1 , and in Eq. 2 the negative class is associated with a first binary label y=1 and a positive class is associated with a second binary label y=0 , optionally wherein m was specified during training as a hyperparameter, or wherein m was optimised during training.

5. The method of claim 3 or claim 4, wherein m was optimised during training and determining, using the distance between the latent space representation of the reference X-ray diffraction spectrum and thelatent space representation of the X-ray diffraction spectrum for the sample, whether the sample comprises the same organic compounds and / or phases of the same organic compounds as those associated with the reference X-ray diffraction spectrum comprises comparing said distance to the optimised value of m or a value derived therefrom.

6. The method of any preceding claim, wherein the deep learning model is a deep neural network comprising one or more convolutional layers, optionally wherein each convolutional layer is a 1 D convolutional layer; and / or wherein the deep learning model has been trained as part of a Siamese neural network architecture.

7. The method of any preceding claim, wherein the deep learning model is a deep neural network comprising a plurality of convolutional layers in parallel associated with respective kernel sizes wherein at least two of the convolutional layers are associated with different kernel sizes, or wherein all convolutional layers are associated with a different kernel size, and / or wherein the deep learning model does not comprise any sequential convolutional layers; optionally wherein the deep neural network comprises a plurality of convolutional layers in parallel associated with kernel sizes between 8 and 128, and / or wherein the deep neural network comprises a plurality of convolutional layers in parallel associated with respective kernel sizes that are different from each other, and / or wherein the deep neural network comprises 3 or 4 convolutional layers in parallel, and / or wherein the outputs of the plurality of convolutional layers in parallel are concatenated or fed to respective additional parallel layers then concatenated.

8. The method of any preceding claim, wherein determining, using a distance between the latent space representation of the reference X-ray diffraction spectrum and the latent space representation of the X-ray diffraction spectrum for the sample, whether the sample comprises the same organic compounds and / or phases of the same organic compounds as those associated with the reference X- ray diffraction spectrum comprises:(a) comparing said distance to a predetermined threshold, wherein when said distance is below the predetermined threshold, the sample is considered to comprise or consist of the same organic compounds and / or phases of the same organic compounds as those associated with the reference X-ray diffraction spectrum, and when said distance is at or above the predetermined threshold, the sample is considered to comprise or consist of different organic compounds and / or different phases of the same organic compounds as those associated with the reference X-ray diffraction spectrum; or(b) comparing said distance to corresponding distances obtained using one or more further reference X-ray diffraction spectra, wherein the sample is considered to comprise the same organic compounds and / or phases of the same organic compounds as those associated with the reference X-ray diffraction spectrum when said distance is one of a set of the one or more smallest distances amongst the distances associated with all reference X-ray diffraction spectra.

9. The method of any preceding claim, wherein the deep learning model has been trained using training data comprising a plurality of training sets of one or more X-ray diffraction spectra, each of the one ormore X-ray diffraction spectra in a set associated with the same organic compound or composition, wherein the deep learning model has been trained using a cross-validation scheme in which one or more complete sets are excluded from the training set at each cross-validation fold.

10. The method of any preceding claim, wherein the deep learning model that has been trained using training data comprising one or more simulated X-ray diffraction spectra, optionally wherein the one or more simulated X-ray diffraction spectra are obtained by: combining a plurality of X-ray diffraction spectra associated with respective organic compounds, obtaining a simulated X-ray diffraction spectrum for an organic compound using a known crystalline structure of the organic compound, and / or obtaining a simulated X-ray diffraction spectrum from a measured or simulated X-ray diffraction spectrum by addition of noise to the measured or simulated X-ray diffraction spectrum.11 . The method of any preceding claim, wherein the sample comprises one or more pharmaceutical compounds, and / or wherein the X-ray diffraction spectrum is an X-ray powder diffraction spectrum.

12. The method of any preceding claim, wherein the method comprises repeating the step of inputting a reference X-ray diffraction spectrum into the deep learning model using one or more further reference X-ray spectra, and repeating the step of determining whether the sample comprises the same compounds and / or phases of the same compounds as those associated with the reference X-ray diffraction spectrum for each of said further reference X-ray spectra, optionally wherein the reference X-ray spectra and further reference X-ray spectra are part of a library of reference X-ray spectra and the method is for determining whether the sample comprises the same organic compounds and / or phases of the same organic compounds as those associated with a reference X-ray diffraction spectrum in the library, or wherein the reference X-ray spectra and further reference X-ray spectra are associated with respective samples and the method is for determining whether any of the samples comprises the same organic compounds and / or phases of the same organic compounds.

13. A method of identifying the presence of one or more polymorphs of a pharmaceutical compound in a sample, or monitoring the quality of a sample of pharmaceutical product, the method comprising: obtaining an X-ray diffraction spectrum for the sample, and characterising the sample using the method of any preceding claim.

14. A method of training a deep learning model for characterising a sample comprising one or more organic compounds, the method comprising: receiving training data comprising a plurality of X-ray diffraction spectra, obtaining pairs of X-ray diffraction spectra assigned with a first binary label and pairs of X-ray diffraction spectra assigned with a second binary label, training a deep learning model to take as input an X-ray diffraction spectrum and produce as output a latent space representation for the input X-ray diffraction spectrum, thereby obtaining a latent space representation for the X-ray diffraction spectrum for the sample,wherein the deep learning model is trained using a contrastive learning loss to produce latent space representations such that pairs of input X-ray diffraction spectra assigned the first binary label have latent space representations that are closer to each other than pairs of input X-ray diffraction spectra assigned the second binary label.

15. A system comprising at least one processor; and at least one non-transitory computer readable medium containing instructions that, when executed by the at least one processor, cause the at least one processor to implement the method of any of claims 1 to 14, optionally wherein the system further comprises an X-ray diffraction scanner.

Citation Information

Cited By

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

    CN122135831A

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

    CN122135831B