目录

结构渲染

misaraty 更新 | 2026-03-06
前言
简述材料和分子结构渲染的方法。

Materials Studio

  • Materials Studio搭建晶体结构的最佳选择;显示效果一般,且售价较高。

VESTA

  • VESTA是文献中最为流行的晶体显示与搭建工具,注意修改Properties-Atoms-Shininess (%)70,显示效果更好。

OVITO

  • OVITO可以将CIF转为POV文件,方便导入POV-Ray中渲染。

Blender

  • 需要先安装BlenderCIF来导入CIF文件。

  • 然后进入C:\Program Files\Blender Foundation\Blender 5.0\5.0\python\bin目录,鼠标右键在此处打开CMD并键入,

1
python.exe -m pip install gemmi
  • 有时VESTA通过POSCAR生成的CIF导入Blender无法识别,需要使用Pymatgen重新生成下,代码如下:
1
2
3
4
5
6
import os
from pymatgen.core import Structure
os.chdir(os.path.dirname(os.path.abspath(__file__)))

structure = Structure.from_file("(QA)PbI4.vasp")
structure.to(filename="(QA)PbI4.cif")
注意

ASE转换的结构可能会报错。

1
2
3
4
5
6
import os
from ase.io import read, write
os.chdir(os.path.dirname(os.path.abspath(__file__)))

atoms = read("(QA)PbI4.vasp")
write("(QA)PbI4.cif", atoms)

RDKit

  • RDKit是文献中主流的分子画图工具。

xyzrender

  • xyzrender画图颜值比RDKit高,也是写这篇文章的主要动力之一。

  • 安装后,替换C:\Users\misar\anaconda3\Lib\site-packages\xyzgraph\data_loader.py

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
"""Molecular reference data loader."""

import json
from dataclasses import dataclass
from importlib import resources
from typing import Dict, FrozenSet, List, Set

BOHR_TO_ANGSTROM = 0.5291772105


@dataclass
class MolecularData:
    """Container for molecular reference data.

    Loaded once on import and accessible globally.
    """

    vdw: Dict[str, float]
    valences: Dict[str, List[int]]
    electrons: Dict[str, int]
    metals: Set[str]
    s2n: Dict[str, int]
    n2s: Dict[int, str]
    electronegativity: Dict[str, float]
    conjugatable_atoms: FrozenSet[str]
    aromatic_atoms: FrozenSet[str]
    scoring_conjugatable_atoms: FrozenSet[str]
    max_aromatic_valence: Dict[str, int]

    _instance = None

    @classmethod
    def get_instance(cls) -> "MolecularData":
        """Get or create instance."""
        if cls._instance is None:
            cls._instance = cls._load_data()
        return cls._instance

    @classmethod
    def _load_data(cls) -> "MolecularData":
        """Load all molecular data from package resources."""
        data_path = resources.files("xyzgraph.data")

        # Load VDW radii
        vdw_file = data_path / "vdw_radii.json"
        with vdw_file.open("r", encoding="utf-8") as f:
            vdw_data = json.load(f)
        vdw_radii = {
            element: vdw_data[element]["vdw_radius"] * BOHR_TO_ANGSTROM
            for element in vdw_data
            if not element.startswith("_")
        }

        # Load expected valences
        try:
            valence_file = data_path / "expected_valences.json"
            with valence_file.open("r", encoding="utf-8") as f:
                valence_data = json.load(f)
            expected_valences = {
                element: valence_data[element] for element in valence_data if not element.startswith("_")
            }
        except Exception as e:
            print(f"Warning: Could not load valences file: {e}, using fallback")
            expected_valences = {
                "H": [1],
                "C": [4],
                "N": [3, 5],
                "O": [2],
                "F": [1],
                "P": [3, 5],
                "S": [2, 4, 6],
                "Cl": [1],
                "Br": [1],
                "I": [1, 2, 3],
                "Li": [1],
                "Na": [1],
                "K": [1],
                "Mg": [2],
                "Ca": [2],
                "Zn": [2],
                "Fe": [2, 3],
                "Cu": [1, 2],
                "Mn": [2, 3, 4],
                "Ru": [2, 3, 4],
            }

        # Load valence electrons
        try:
            ve_file = data_path / "valence_electrons.json"
            with ve_file.open("r", encoding="utf-8") as f:
                ve_data = json.load(f)
            valence_electrons = {el: ve_data[el] for el in ve_data if not el.startswith("_")}
        except Exception as e:
            print(f"Warning: Could not load valence electrons file: {e}, using fallback")
            valence_electrons = {
                "H": 1,
                "C": 4,
                "N": 5,
                "O": 6,
                "F": 7,
                "P": 5,
                "S": 6,
                "Cl": 7,
                "Br": 7,
                "I": 7,
            }

        # Define metals set
        metals = {
            "Li",
            "Na",
            "K",
            "Mg",
            "Ca",
            "Zn",
            "Sc",
            "Ti",
            "V",
            "Cr",
            "Mn",
            "Fe",
            "Co",
            "Ni",
            "Cu",
            "Y",
            "Zr",
            "Nb",
            "Mo",
            "Tc",
            "Ru",
            "Rh",
            "Pd",
            "Ag",
            "Cd",
            "Hf",
            "Ta",
            "W",
            "Re",
            "Os",
            "Ir",
            "Pt",
            "Au",
            "Hg",
            "Al",
            "Ga",
            "In",
            "Sn",
            "Pb",
            "La",
            "Ce",
            "Pr",
            "Nd",
            "Sm",
            "Eu",
            "Gd",
            "Tb",
            "Dy",
            "Ho",
            "Er",
            "Tm",
            "Yb",
            "Lu",
        }

        # Load element mappings
        element_file = data_path / "atom_symbols.json"
        with element_file.open("r", encoding="utf-8") as f:
            s2n = json.load(f)
        n2s = {v: k for k, v in s2n.items()}

        # Pauling electronegativity (determines which atom carries charge)
        electronegativity = {
            "H": 2.2,
            "C": 2.5,
            "N": 3.0,
            "O": 3.5,
            "F": 4.0,
            "P": 2.2,
            "S": 2.6,
            "Cl": 3.2,
            "Br": 3.0,
            "I": 2.7,
        }

        # Atoms eligible for Kekulé pattern initialization
        conjugatable_atoms = frozenset({"C", "N", "O", "S", "B", "P", "Se"})

        # Atoms that receive aromatic bond order 1.5
        aromatic_atoms = frozenset({"C", "N", "O", "S", "B"})

        # Atoms checked for conjugation penalty in scoring
        scoring_conjugatable_atoms = frozenset({"C", "N", "O", "S", "P"})

        # Max bond order sum for aromatic ring members
        max_aromatic_valence = {"H": 1, "B": 3, "C": 4, "N": 3, "O": 2, "P": 3, "S": 2, "Se": 2}

        return cls(
            vdw=vdw_radii,
            valences=expected_valences,
            electrons=valence_electrons,
            metals=metals,
            s2n=s2n,
            n2s=n2s,
            electronegativity=electronegativity,
            conjugatable_atoms=conjugatable_atoms,
            aromatic_atoms=aromatic_atoms,
            scoring_conjugatable_atoms=scoring_conjugatable_atoms,
            max_aromatic_valence=max_aromatic_valence,
        )


# Eagerly instantiate on module import
DATA = MolecularData.get_instance()

否则会报UTF-8编码错误。

  • 运行xyzrender (QA)PbI4.xyz --config paton --hy --vdw -S 1000 -o render.png
分子渲染图