WorksPhysics and Astronomy
Generative Inverse Design of Crystal Structures via Diffusion Models with Transformers
Abstract
Recent advances in deep learning have enabled the generation of realistic data by training generative models on large datasets of text, images, and audio. While these models have demonstrated exceptional performance in generating novel and plausible data, it remains an open question whether they can effectively accelerate scientific discovery through the data generation and drive significant advancements across various scientific fields. In particular, the discovery of new inorganic materials with promising properties poses a critical challenge, both scientifically and for industrial applications. However, unlike textual or image data, materials, or more specifically crystal structures, consist of multiple types of variables - including lattice vectors, atom positions, and atomic species. This complexity in data give rise to a variety of approaches for representing and generating such data. Consequently, the design choices of generative models for crystal structures remain an open question. In this study, we explore a new type of diffusion model for the generative inverse design of crystal structures, with a backbone based on a Transformer architecture. We demonstrate our models are superior to previous methods in their versatility for generating crystal structures with desired properties. Furthermore, our empirical results suggest that the optimal conditioning methods vary depending on the dataset.
Introduction
The advancements in artificial intelligence, particularly in the domains of large language models and generative AI for image and audio synthesis, are having a significant impact on our social lives [27] (Rombach et al. 2022). Such advancements in AI are also expected to accelerate research and development in materials science, which could potentially drive scientific discoveries and accelerate the development of materials. The discovery of novel materials, for example catalysis, battery materials, and superconducting materials, holds the potential to enable innovation in a wide range of industries [Toyao et al., 2020; Chen et al., 2020a].
Traditionally, the exploration of materials has required repeated try-and-error, consuming enormous amounts of time and effort. If novel and promising materials could be discovered in-silico, i.e., on computers, the exploration process could be further accelerated. Based on this concept, high-throughput virtual screenings using density functional theory (DFT) simulations or machine learning-based predictive models have been employed [Noh et al., 2020]. However, such screening-based approaches have required enumerating and comprehensively simulating a vast number of candidate materials. If it were possible to selectively enumerate promising materials or directly generate materials with desired properties, the process of materials research and development would be significantly streamlined. To address these challenges, the inverse design of materials using deep generative models has emerged as a potential approach.
Materials, or more specifically crystal structures, consist of multiple types of variables including lattice vectors, atomic coordinates, and atomic species. There are several ways to represent crystal structures in a computational framework, and several approaches can be employed to generate them. Moreover, the inverse design requires generating crystal structures with desired properties rather than just generating them in a random manner, where several strategies can be employed to achieve this [Noh et al., 2019; Xie et al., 2021; Yang et al., 2023; Zeni et al., 2023]. In other words, there are various design choices for constructing the generative models for the inverse design of crystal structures.
Diffusion models are a type of generative model that have exhibited distinguished performance, particularly in the domain of image generation [34] (Ho et al. 2020). They have also demonstrated its versatility and effectiveness in generating audio waveforms [Chen et al., 2020b; Kong et al., 2021], molecular and protein design [Hoogeboom et al., 2022; Watson et al., 2023], as well as crystal structure generation [Yang et al., 2023; Jiao et al., 2023; Zeni et al., 2023]. In diffusion models, data is generated by progressively denoising an initial random input. For image generation tasks, variants of U-Net [Ronneberger et al., 2015] based on convolutional neural networks (CNNs) have been used as the backbone for the denoising process. Recently, diffusion models replacing the U-Net with a Vision Transformers (ViTs) [Dosovitskiy et al., 2021] have also been proposed, with the aim of improving scalability and enhanceing the quality of generated data [28] (Hatamizadeh et al. 2023). This suggests that the examination of the backbone model in diffusion models can have a significant impact on the overall model performance.
In this study, we explore a new type of diffusion model for generative inverse design of crystal structures, where a Transformer [Vaswani et al., 2017] architecture is utilized for the backbone to handle interactions between atoms. Furthermore, we explore suitable conditioning methods for the high-precision inverse design of crystal structures incorporating ideas developed in other domains such as image generation, and provide solid baselines for future research on generative crystal structure design techniques. Ultimately, we demonstrate that our proposed model is capable of performing inverse design with accuracy equal to or exceeding that of prior methods.
Preliminary
Representation of Crystal Structure
Crystal structure is characterized by the periodic arrangement of atoms in three-dimensional space. The crystal structure can be defined using a repeating unit called unit cell. When a unit cell contains atoms, the crystal structure can be represented as , where is the lattice matrix containing the lattice vectors of the unit cell, is the atomic coordinates in the Cartesian coordinate system, and is the corresponding atomic species. is called the fractional coordinate, which is advantageous for representing atomic positions in crystal structures considering their periodic nature. Therefore, the crystal structure can also be represented as , where denotes the fractional coordinate matrix. A conceptual diagram of a crystal structure represented in two dimensions for simplicity is shown in Figure 1.

Figure 1. A conceptual diagram of a crystal structure represented in 2D for intuitive understanding. The red arrows represent the lattice vectors of the unit cell, while colored dots represent atoms, with the colors corresponding to different atomic species. The gray region highlights the area of the unit cell.
Property optimization
To explore the potential of generative model for inverse design, this study focuses on property optimization given target property values, rather than random materials generation, i.e., ab initio generation. Property optimization is a task that aims to generate crystal structures possessing target properties.
Related Work
Diffusion Models for Structured Data
Diffusion models are a class of generative models originally proposed for image generation, with two main formulation based on Denoising Diffusion Probabilistic Models (DDPMs) [Ho et al., 2020] and Noise Conditional Score Networks (NCSCs) [34], where data is generated from the noise with the same dimension. Diffusion models have also been applied to other structured data, such as text [Hoogeboom et al., 2021], point cloud [21] and graphs [Vignac et al., 2023].
When applying to crystal structure generation, it is necessary to jointly model continuous variables, such as lattice vectors and atomic coordinates, alongside discrete variables, like atom types. Furthermore, to take into account the translational, rotational, and periodic invariance of crystal structures, it is necessary to consider the rotational equivariance of lattice vectors and the periodic invariance of fractional coordinates [Jiao et al., 2023], which requires careful design of the denoising model architecture.
Transformers for Recognition and Generation
Transformer is a neural network architecture that was originally proposed for natural language processing (NLP) tasks [Vaswani et al., 2017]. The self-attention mechanism in Transformers effectively captures long-range dependencies and efficiently encodes input sequences, leading to its success across various domains beyond NLP.
One prominent example of their application is in the field of computer vision. Vision Transformers (ViTs), which incorporate attention mechanisms to capture dependencies between image patches, have demonstrated superior performance compared to CNN-based models in image recognition tasks [Dosovitskiy et al., 2021]. Due to this advantage, ViTs have recently been increasingly employed as backbone models for diffusion models in image generation tasks [28] (Gao et al. 2023; Hatamizadeh et al. 2023).
Furthermore, the application of Transformer-based models has advanced in domains related to materials science. For instance, self-attention mechanisms have been utilized to model the complex relationship between atoms within materials. This approach has enabled the effective representation learning of the 3D structures of molecules [Ying et al., 2021] and materials [Yan et al., 2022; Yan et al., 2024; Taniai et al., 2024], facilitating the accurate prediction of materials properties. Our study aims to leverage the power of self-attention mechanisms to model inter-atomic interactions, which is then used as the backbone of a diffusion model for crystal structure generation.
Generative Models for Crystal Generation
Generative models for crystal structures are essentially models designed to create representations of crystal structures . In general, these models can be designed based on two aspects: how crystal structures are represented in a computational framework and how those representations are generated. Typical invertible crystal structure representations include 2D arrays containing crystallographic information on [Ren et al., 2022], voxel images [Hoffmann et al., 2019; Court et al., 2020; Noh et al., 2019], and graphs [Xie et al., 2021; Luo et al., 2023; Zeni et al., 2023]. Regarding the generation methods, generative frameworks originally developed for image generation, such as Variational Autoencoders (VAEs) [Hoffmann et al., 2019; Court et al., 2020; Ren et al., 2022; Xie et al., 2021; Luo et al., 2023], Generative Adversarial Networks [Nouira et al., 2018; Zhao et al., 2021], and diffusion models [Xie et al., 2021; Luo et al., 2023; Zeni et al., 2023; Yang et al., 2023; Jiao et al., 2023], have been widely adopted.
Many previous studies have focused on generating crystal structures for a limited range of crystal systems, such as cubic crystals, or for systems with a limited number of elements, such as binary or ternary compounds. However, recently, versatile generative models capable of generating diverse and plausible crystal structures across various crystal systems and elemental compositions have been developed. [1] (Xie et al. 2021; Luo et al. 2023; Yang et al. 2023; Jiao et al. 2023). Xie et al. [2021] proposed CDVAE, a model that combines VAE and diffusion models, where crystal structures are represented as graphs. They demonstrated that the model is capable of generating diverse and reasonable crystal structures by learning the Cartesian coordinate scores using a graph neural network (GNN) as the backbone. Zeni et al. proposed a diffusion model that jointly generates , , and , which uses graphs as a representation of crystal structures, and the backbone model is based on a GNN [Zeni et al., 2023]. A diffusion generative model by Yang et al. uses a well designed representation called UniMat, and its backbone is based on a U-Net [Yang et al., 2023]. In our diffusion model, atoms are treated as a point cloud in fractional space, and the backbone model is formulated based on a Transformer.
Methodology
In this section, we introduce our proposed model for the generative inverse design of crystal structures. We first introduce the joint diffusion framework in Sec. 4.1. In Sec. 4.2, an overview of the base architecture of the transformer model is provided, and in Sec. 4.3, two approaches of conditional generation for the generative inverse design of crystal structures are described.
Joint Diffusion Framework
As a general concept, a diffusion model defines two Markov processes: a fixed forward diffusion process that gradually adds noise to the original data over steps, from to , and a learned generative process that removes the noise from the prior .
Diffusion on Lattices
For lattice vectors with continuous variables, the forward diffusion process can be defined as follows [Jiao et al., 2023], according to DDPM [Ho et al., 2020]:
Here, is the predefined noise schedule, and is the identity matrix. By applying the Markov property, can be directly derived from as:
where and . By the reparameterization trick, can be written as , where .
In the backward process, the lattice vectors are represented using a Gaussian distribution , where and . The neural network is trained to predict , given and , with the loss function
Diffusion on Coordinates
While fractional coordinates are convenient for handling periodicity, applying DDPM with Gaussian functions is not appropriate. Therefore, score-matching based models [34, 34, 35] have been adopted together with wrapped normal (WN) distribution [Jiao et al., 2023; Zeni et al., 2023]. In this case, we assume that follows the perturbed distribution with a predefined noise schedule as follows:
where denotes a WN distribution, and is defined using a hyper parameter as and for .
In the backward process, the output of neural network estimates the score of perturbed data distribution, where the neural network is trained with the objective:
Here, is approximated via Monte Carlo Sampling, and the data is generated by the ancestral predictor with the Langevin corrector, as detailed in [Jiao et al., 2023].
Diffusion on Species
There are several possible approaches to modelling the diffusion of atomic species; however, in this study, we consider them as categorical data and apply discrete denoising diffusion probabilistic models (D3PMs) [Austin et al., 2023; Hoogeboom et al., 2021], as employed in the previous works [Guan et al., 2023; Peng et al., 2023; Zeni et al., 2023].
In D3PM, the forward diffusion process is formulated using categorical distribution with probability vector as:
where is the one-hot row-vector representation of atomic species at timestep , is the transition matrix, and is the number of classes. The Markov property allows for directly computing from as follows:
with . In this study, we define transition matrix as so that atomic species follow a uniform distribution at , which was selected based on experiments.
The backward process is modeled using categorical distribution , wherein is predicted by the neural network, which is trained with the loss function:
Backbone Denoising Model
The overview of the base model architecture is shown in Figure 2 (a). Under the joint diffusion processes defined in § 4.1, we construct a model that receives as input and outputs , , and . In the following, we describe several key components of the model.

Figure 2. (a) Overview of the base model architecture. (b) Overview of the conditional model with condition-dependent initialization method. (c) Overview of the conditional model with condition-dependent self-attention method. The models of crystal structures in this figure were visualized using VESTA [23].
Input Embedding
As shown in Figure 2, initial input embedding in a unit cell, , which is fed into the self-attention block, is generated based on time-dependent atomic species . We generate -dimensional species embedding and set , where MLP denotes a simple multi-layer perceptron.
Self-Attention Block
The Self-Attention block, which serves as a core component of the proposed model, receives , , and as inputs, and outputs an updated , where denotes block index . Following the original Transformer [Vaswani et al., 2017], is updated as follows:
where MHA and LN denote multi-head attention layer and layer normalization [Ba et al., 2016], respectively.
In this work, the attention mechanism in the MHA layer relies on self-attention with relative position representations [Shaw et al., 2018] to better incorporate relative positional relationships between atoms. Specifically, input sequences are transformed to according to the following equation:
Here, , and , , , where , , are parameter matrices for query, key, and value, respectively.
The terms and serve as biases to incorporate the relative positional relationship between atoms and . In this study, we consider generating these terms from and . Specifically, to incorporate information about the relative positions of atom and in fractional space, a Fourier transformation , which is first proposed in [Jiao et al., 2023] for creating periodic-invariant message in GNN, is utilized alongside to get and as follows:
Here, the is defined as:
where is an index that runs over the dimension of 3D coordinates, and is an index that runs over the dimensions of the embedding vector. In practice, and are flattened and concatenated before being fed into MLP.
Transformer Decoder
After updating through the -layer self-attention blocks, the transformer decoder receives and , and then predicts , , and . and are obtained straightforwardly from through the equations
and
is obtained by the linear transformation of as
where denotes an MLP that outputs a matrix. We note that this procedure follows the steps performed in the readout of GNN [Jiao et al., 2023], and enables prediction of that is equivariant to the rotation of .
Conditioning Methods
In this study, we perform conditional generation, using physical property values as condition, for the generative inverse design of crystal structures. We provide the model with the time step and property values as conditions, where time step is transformed into a feature vector using sinusoidal positional encoding [Vaswani et al., 2017; Ho et al., 2020], while property values are mapped to a vector via linear projection. The condition embedding is constructed from and as follows:
where denotes the concatenation of two vectors. As described below, we investigate two conditional generation approaches based on how is fed into the model.
Condition Dependent Initialization (CDI)
The first approach is to make the input embedding condition-dependent, as shown in Figure 2 (b). In this case, input embedding is set using not only the species embedding but also the condition embedding as follows:
The model conditioned with condition-dependent initialization is referred to as MODEL-CDI.
Condition Dependent Self-attention (CDS)
Figure 2 (c) shows the second approach, where is fed into every self-attention block. Similar to the Time-dependent Self-attention mechanism proposed in DiffiT [Hatamizadeh et al., 2023], the attention block takes as an additional input, and the query, key, value are made condition-dependent as follows:
where , , are the conditional projection matrices for query, key, and value, respectively. The model conditioned with this condition-dependent self-attention is referred to as MODEL-CDS.
Experiments
In this section, we evaluate the performance of our proposed models on the task of property optimization. Through the comparison with existing methods, we show that our proposed models are effective for generative inverse design of crystal structures. In this work, we set , , and the number of attention heads was set to 3.
Experimental Setup
Task definition
Property optimization is a task that aims to generate crystal structures that possess desired physical properties when target property values are provided.
Datasets
To evaluate the performance of the proposed models across diverse materials systems, we conduct the assessments on three datasets with different compositions and crystal systems, following Xie et al. [Xie et al., 2021]. Perov-5 [Castelli et al., 2012a; Castelli et al., 2012b] is a dataset of crystal structures derived from cubic perovskite, containing 18,928 crystal structures and their corresponding property values. Carbon-24 [30] contains 10,153 structures consisting solely of carbon atoms, with each structure including between 6 and 24 atoms. MP-20 [Jain et al., 2013] is a collection of stable crystal structures from the Materials Project database, each containing 20 atoms or fewer. MP-20 includes a total of 45,231 structures and is the most diverse dataset in terms of both composition and crystal systems. Following [Xie et al., 2021], each dataset was split into a ratio of 6:2:2 for training, validation, and testing, respectively.
Metrics
In the property optimization task of this study, we measure the ability of generative models to generate crystal structures with low formation energies, in other words, to generate stable crystal structures. In this research, we perform conditional generation of crystal structures by providing the minimum values of the physical properties in the training dataset as conditional values, and calculate the success rate (SR). The success rate is calculated as the proportion of generated crystal structures whose physical property values fall within the top 5% (SR5), 10% (SR10), and 15% (SR15) of the target values. The property values were calculated using pre-trained GNN model by Xie et al. [Xie et al., 2021].
Baselines
We compare our models with two existing methods: CD-VAE [Xie et al., 2021] and SyMat [Luo et al., 2023], both of which are crystal structure generation models that combine VAE and score-based diffusion models, and they can be applied to the property optimization. Other diffusion models, such as MatterGen [Zeni et al., 2023] and UniMat [Yang et al., 2023], were not compared because source codes are not open at present and were not assessed on the same metrics.
Results
The performance of property optimization is reported in Table 1. For both Perov-5 and Carbon-24, our proposed models (MODEL-CDI and MODEL-CDS) demonstrated superior performance compared to the previous methods (CDVAE and SyMat). Notably, for Perov-5, MODEL-CDS yielded SRs of nearly 1.0, while for Carbon-24, the , which was close to 0.0 with previous methods, increased to above 0.5. On the other hand, for MP-20, using MODEL-CDI achieved SRs as high as that of SyMat, while MODEL-CDS resulted in a slightly lower SRs. The fact that the proposed models demonstrated overall good performance suggests that Transformers can also be applied as the backbone in diffusion models for crystal structure generation. In addition, as shown in Table 1, MODEL-CDI demonstrated SRs close to the best across all datasets. This indicates that MODEL-CDI is a versatile model capable of being applied to the task of generating crystal structures with desired properties across a wide variety of datasets.
| Method | Perov-5 | Carbon-24 | MP-20 | ||||||
| SR5 | SR10 | SR15 | SR5 | SR10 | SR15 | SR5 | SR10 | SR15 | |
| CDVAE [Xie et al., 2021] | 0.52 | 0.65 | 0.79 | 0.00 | 0.06 | 0.06 | 0.78 | 0.86 | 0.90 |
| SyMat [Luo et al., 2023] | 0.73 | 0.80 | 0.87 | 0.06 | 0.13 | 0.13 | 0.92 | 0.97 | 0.97 |
| MODEL-CDI | <u>0.93</u> | <u>0.97</u> | <u>0.98</u> | <u>0.43</u> | <u>0.56</u> | <u>0.57</u> | <u>0.91</u> | <u>0.93</u> | <u>0.95</u> |
| MODEL-CDS | 0.97 | 0.99 | 1.00 | 0.56 | 0.64 | 0.64 | 0.63 | 0.75 | 0.84 |
Table 1. Property optimization performance, where SR stands for success rate. The highest SR and the second highest SR achieved among the four models are emphasized with bold and underline, respectively. Performance of CDVAE and SyMat were obtained from the original literatures.
It is interesting to note that when comparing the performance of MODEL-CDI and MODEL-CDS, MODEL-CDS demonstrated higher performance on Perov-5 and Carbon-24, while MODEL-CDI exhibited better performance on MP-20. From the perspective of the crystal structure distribution, Perov-5 has a high degree of freedom in composition, while Carbon-24 has a high degree of freedom in crystal systems. MP-20, on the other hand, has high degrees of freedom in both composition and crystal systems. Therefore, it is conceivable that the factors determining the property values, particularly the formation energy in this case, vary depending on the dataset. The difference in performance between MODEL-CDI and MODEL-CDS in this study is considered to reflect this differences of characteristics of datasets, indicating that the optimal conditioning method varies depending on the dataset. The optimal method for conditional generation may also vary depending on the model architecture and the target properties. Therefore, exploring suitable conditional generation techniques is expected to be a valuable direction for future research.
Conclusion and Future Work
In this work, we explored a new diffusion model for generative inverse design of crystal structures, where the backbone is formulated based on a Transformer architecture. We explored two conditioning methods for generating crystal structures with target physical properties. Our models generally demonstrated comparable or superior performance compared to previous methods. Furthermore, it was found that the optimal conditioning method varies depending on the dataset, suggesting that the exploration of conditioning techniques depending on the dataset and property would be important for high-precision inverse design.
As future work, evaluation using DFT calculations will be necessary for more rigorous assessments. Additionally, the novelty and diversity of the inversely designed crystal structures will also become important metrics in the discovery of new materials.
Acknowledgements
This work was supported by JSPS KAKENHI Grant Numbers JP19H05787, 24KJ0939, and JST CREST Grand Number JPMJCR1993. I.T was supported by the Program for Leading Graduate Schools (MERIT-WINGS).
Conflict of Interest
The authors have no conflicts to disclose.
References
- [1] [AI4Science et al., 2023] Mila Hernandez-Garcia, Alexandre Duval, Alexandra Volk hova, Yoshua Bengio, Divya Sharma, Pierre Luc Carrier, Yasmine Benabed, Michal Koziarski, and Victor Schmidt. Crystal-gnf: sampling crystals with desirable properties and constraints. arXiv preprint arXiv:2310.04925, 2023.
- [21]Luo and Hu, 2021] Shitong Luo and Wei Hu. Diffusion probabilistic models for 3d point cloud generation. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pages 2837–2845, June 2021.arxiv.org/abs/2103.01458
- [23]Momma and Izumi, 2008] Koichi Momma and Fujio Izumi. VESTA: a three-dimensional visualization system for electronic and structural analysis. Journal of Applied Crystallography, 41(3):653–658, 2008.DOI
- [27]OpenAI, 2023] OpenAI. Gpt-4 technical report. arXiv preprint arXiv:2303.08774, 2023.arxiv.org/abs/2303.08774
- [28]Peebles and Xie, 2022] William Peebles and Saining Xie. Scalable diffusion models with transformers. arXiv preprint arXiv:2212.09748, 2022.arxiv.org/abs/2212.09748
- [30]Pickard, 2020] Chris J. Pickard. Airss data for carbon at 10gpa and the c+n+h=o system at 1gpa. 2020.
- [34][Song and Ermon, 2019] Yang Song and Stefano Ermon. Generative modeling by estimating gradients of the data distribution. arXiv preprint arXiv:1907.05600, 2019.arxiv.org/abs/1907.05600
- [35][Song and Ermon, 2020] Yang Song and Stefano Ermon. Improved techniques for training score-based generative models. arXiv preprint arXiv:2006.09011, 2020.arxiv.org/abs/2006.09011