From 82ad5654480180c27916e5d69a04cb26743daa28 Mon Sep 17 00:00:00 2001 From: Haonan Chen Date: Thu, 8 Jan 2026 12:30:05 +0800 Subject: [PATCH] =?UTF-8?q?AtomTranslation=20=E6=94=B9=E4=B8=BA=E4=BB=A5?= =?UTF-8?q?=E8=B6=85=E8=83=9E=E6=99=B6=E6=A0=BC=E7=9F=A2=E4=B8=BA=E5=8D=95?= =?UTF-8?q?=E4=BD=8D=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=98=AF=E4=BB=A5=E5=9F=83?= =?UTF-8?q?=E4=B8=BA=E5=8D=95=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/project-to-mode.cpp | 16 ++++++++-------- test/unfold/config.yaml | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/project-to-mode.cpp b/src/project-to-mode.cpp index d5a0e6d..022f0b9 100644 --- a/src/project-to-mode.cpp +++ b/src/project-to-mode.cpp @@ -40,15 +40,16 @@ void ufo::project_to_mode(std::string config_file) biu::Logger::Guard log; std::vector basis(config.PrimativeCellBasisNumber.array().prod()); for (auto [xyz_of_basis, i_of_basis] - : biu::sequence(config.PrimativeCellBasisNumber.cast().eval())) + : biu::sequence(config.PrimativeCellBasisNumber)) { // 波矢就是 xyz_of_basis, 单位为单胞的倒格矢 // 将它的单位转换成埃^-1 - auto wavevector = input.Primative.Cell.inverse() * xyz_of_basis.cast(); + auto wavevector = + (xyz_of_basis.transpose().cast() * input.Primative.Cell.inverse().transpose()).transpose().eval(); log.debug("xyz_of_basis: {}"_f(xyz_of_basis)); log.debug("wavevector: {:.3f}"_f(fmt::join(wavevector, ", "))); // 将原子坐标单位也转换为埃 - auto atom_position = input.Primative.AtomPosition * input.Primative.Cell; + auto atom_position = (input.Primative.AtomPosition * input.Primative.Cell).eval(); // 计算基矢 basis[i_of_basis] = (2i * std::numbers::pi_v * (atom_position * wavevector)).array().exp(); } @@ -82,12 +83,11 @@ void ufo::project_to_mode(std::string config_file) auto wavevector = input.Primative.Cell.inverse() * wavevector_by_reciprocal_primative_cell; log.debug("wavevector: {}"_f(wavevector)); // 将原子坐标单位也转换为埃 - Eigen::MatrixX3d atom_position = input.Super.AtomPosition + auto atom_translation = + (input.Super.AtomTranslation.value_or(std::array{0., 0., 0.}) | biu::toEigen<>) + .transpose().replicate(input.Super.AtomPosition.rows(), 1).eval(); + Eigen::MatrixX3d atom_position = (input.Super.AtomPosition - atom_translation) * (input.Super.CellDeformation * input.Super.CellMultiplier.cast().asDiagonal() * input.Primative.Cell); - // 如果在制作模型的过程中,原子有移动过,需要减掉这个移动 - if (input.Super.AtomTranslation) - atom_position -= (input.Super.AtomTranslation.value_or(std::array{0., 0., 0.}) | biu::toEigen<>) - .transpose().replicate(atom_position.rows(), 1); // 计算基矢 basis[i_of_basis] = (2i * std::numbers::pi_v * (atom_position * wavevector)).array().exp(); } diff --git a/test/unfold/config.yaml b/test/unfold/config.yaml index e7ef16a..eb87ec3 100644 --- a/test/unfold/config.yaml +++ b/test/unfold/config.yaml @@ -3,7 +3,7 @@ SuperCellDeformation: - [ 1, 0, 0 ] - [ 0.5, 1, 0 ] - [ 0, 0, 1 ] -AtomTranslation: [ 0, 0, 5.0548836 ] +AtomTranslation: [ 0, 0, 0.5 ] PrimativeCellBasisNumber: [ 8, 8, 8 ] PrimativePhonopy: primitive-phonopy.yaml PrimativeQpoint: primitive-band.hdf5