@@ -536,268 +536,6 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
536536 } // end deepks_out_labels == 1
537537 } // end bandgap label
538538
539- if (PARAM.inp .deepks_bandgap == 2 )
540- {
541- const int nocc = (PARAM.inp .nelec + 1 ) / 2 ;
542- const int range = PARAM.inp .deepks_band_range [1 ] - PARAM.inp .deepks_band_range [0 ];
543- ModuleBase::matrix o_tot (nks, range);
544- for (int iks = 0 ; iks < nks; ++iks)
545- {
546- // record band gap for each k point (including spin)
547- for (int ib = 0 ; ib <= range; ++ib)
548- {
549- if (ib + PARAM.inp .deepks_band_range [0 ] < -1 )
550- {
551- o_tot (iks, ib) = ekb (iks, nocc + ib + PARAM.inp .deepks_band_range [0 ]) - ekb (iks, nocc - 1 );
552- }
553- if (ib + PARAM.inp .deepks_band_range [0 ] > -1 )
554- {
555- o_tot (iks, ib - 1 ) = ekb (iks, nocc + ib + PARAM.inp .deepks_band_range [0 ]) - ekb (iks, nocc -1 );
556- }
557- }
558- }
559-
560- const std::string file_otot
561- = PARAM.globalv .global_out_dir
562- + (PARAM.inp .deepks_out_labels == 1 ? " deepks_otot.npy" : " deepks_orbital.npy" );
563- LCAO_deepks_io::save_matrix2npy (file_otot, o_tot, rank); // Unit: Hartree
564-
565- if (PARAM.inp .deepks_out_labels == 1 ) // don't need these when deepks_out_labels == 2
566- {
567- if (PARAM.inp .deepks_scf )
568- {
569- std::vector<ModuleBase::matrix> wg_hl_range (range);
570- std::vector<std::vector<TH>> dm_bandgap_range (range);
571-
572- // Calculate O_delta
573- for (int ir = 0 ; ir <= range; ++ir)
574- {
575- if (ir + PARAM.inp .deepks_band_range [0 ] < -1 )
576- {
577- wg_hl_range[ir].create (nks, PARAM.inp .nbands );
578- wg_hl_range[ir].zero_out ();
579- dm_bandgap_range[ir].resize (nks);
580- for (int iks = 0 ; iks < nks; ++iks)
581- {
582- wg_hl_range[ir](iks, nocc - 1 ) = -1.0 ;
583- wg_hl_range[ir](iks, nocc + ir + PARAM.inp .deepks_band_range [0 ]) = 1.0 ;
584- }
585- elecstate::cal_dm (ParaV, wg_hl_range[ir], psi, dm_bandgap_range[ir]);
586- }
587- if (ir + PARAM.inp .deepks_band_range [0 ] > -1 )
588- {
589- wg_hl_range[ir - 1 ].create (nks, PARAM.inp .nbands );
590- wg_hl_range[ir - 1 ].zero_out ();
591- dm_bandgap_range[ir - 1 ].resize (nks);
592- for (int iks = 0 ; iks < nks; ++iks)
593- {
594- wg_hl_range[ir - 1 ](iks, nocc - 1 ) = -1.0 ;
595- wg_hl_range[ir - 1 ](iks, nocc + ir + PARAM.inp .deepks_band_range [0 ]) = 1.0 ;
596- }
597- elecstate::cal_dm (ParaV, wg_hl_range[ir - 1 ], psi, dm_bandgap_range[ir - 1 ]);
598- }
599- }
600-
601- ModuleBase::matrix o_delta (nks, range);
602- torch::Tensor orbital_precalc_range;
603-
604- for (int ir = 0 ; ir < range; ++ir)
605- {
606- torch::Tensor orbital_precalc_temp;
607- ModuleBase::matrix o_delta_temp (nks, 1 );
608- DeePKS_domain::cal_orbital_precalc<TK, TH>(dm_bandgap_range[ir],
609- lmaxd,
610- inlmax,
611- nat,
612- nks,
613- inl2l,
614- kvec_d,
615- phialpha,
616- gevdm,
617- inl_index,
618- ucell,
619- orb,
620- *ParaV,
621- GridD,
622- orbital_precalc_temp);
623- if (ir == 0 )
624- {
625- orbital_precalc_range = orbital_precalc_temp;
626- }
627- else
628- {
629- orbital_precalc_range = torch::cat ({orbital_precalc_range, orbital_precalc_temp}, 0 );
630- }
631-
632- DeePKS_domain::cal_o_delta<TK, TH>(dm_bandgap_range[ir], *h_delta, o_delta_temp, *ParaV, nks, nspin);
633- for (int iks = 0 ; iks < nks; ++iks)
634- {
635- o_delta (iks, ir) = o_delta_temp (iks, 0 );
636- }
637- }
638-
639- // save obase and orbital_precalc
640- const std::string file_orbpre = PARAM.globalv .global_out_dir + " deepks_orbpre.npy" ;
641- LCAO_deepks_io::save_tensor2npy<double >(file_orbpre, orbital_precalc_range, rank);
642-
643- const std::string file_obase = PARAM.globalv .global_out_dir + " deepks_obase.npy" ;
644- LCAO_deepks_io::save_matrix2npy (file_obase, o_tot - o_delta, rank); // Unit: Hartree
645- } // end deepks_scf == 1
646- else // deepks_scf == 0
647- {
648- const std::string file_obase = PARAM.globalv .global_out_dir + " deepks_obase.npy" ;
649- LCAO_deepks_io::save_matrix2npy (file_obase, o_tot, rank); // no scf, o_tot=o_base
650- } // end deepks_scf == 0
651- } // end deepks_out_labels == 1
652- } // end bandgap label
653-
654- if (PARAM.inp .deepks_bandgap == 3 )
655- {
656- const int nocc = (PARAM.inp .nelec + 1 ) / 2 ;
657- ModuleBase::matrix o_tot (nks, 1 );
658- for (int iks = 0 ; iks < nks; ++iks)
659- {
660- // record band gap for each k point (including spin)
661- o_tot (iks, 0 ) = ekb (iks, nocc + PARAM.inp .deepks_band_range [1 ]) - ekb (iks, nocc + PARAM.inp .deepks_band_range [0 ]);
662- }
663-
664- const std::string file_otot
665- = PARAM.globalv .global_out_dir
666- + (PARAM.inp .deepks_out_labels == 1 ? " deepks_otot.npy" : " deepks_orbital.npy" );
667- LCAO_deepks_io::save_matrix2npy (file_otot, o_tot, rank); // Unit: Hartree
668-
669- if (PARAM.inp .deepks_out_labels == 1 ) // don't need these when deepks_out_labels == 2
670- {
671- if (PARAM.inp .deepks_scf )
672- {
673- ModuleBase::matrix wg_hl;
674- std::vector<TH> dm_bandgap;
675-
676- // Calculate O_delta
677- wg_hl.create (nks, PARAM.inp .nbands );
678- dm_bandgap.resize (nks);
679- wg_hl.zero_out ();
680- for (int iks = 0 ; iks < nks; ++iks)
681- {
682- wg_hl (iks, nocc + PARAM.inp .deepks_band_range [0 ]) = -1.0 ;
683- wg_hl (iks, nocc + PARAM.inp .deepks_band_range [1 ]) = 1.0 ;
684- }
685- elecstate::cal_dm (ParaV, wg_hl, psi, dm_bandgap);
686-
687- ModuleBase::matrix o_delta (nks, 1 );
688-
689- // calculate and save orbital_precalc: [nks,NAt,NDscrpt]
690- torch::Tensor orbital_precalc;
691- DeePKS_domain::cal_orbital_precalc<TK, TH>(dm_bandgap,
692- lmaxd,
693- inlmax,
694- nat,
695- nks,
696- inl2l,
697- kvec_d,
698- phialpha,
699- gevdm,
700- inl_index,
701- ucell,
702- orb,
703- *ParaV,
704- GridD,
705- orbital_precalc);
706- DeePKS_domain::cal_o_delta<TK, TH>(dm_bandgap, *h_delta, o_delta, *ParaV, nks, nspin);
707-
708- // save obase and orbital_precalc
709- const std::string file_orbpre = PARAM.globalv .global_out_dir + " deepks_orbpre.npy" ;
710- LCAO_deepks_io::save_tensor2npy<double >(file_orbpre, orbital_precalc, rank);
711-
712- const std::string file_obase = PARAM.globalv .global_out_dir + " deepks_obase.npy" ;
713- LCAO_deepks_io::save_matrix2npy (file_obase, o_tot - o_delta, rank); // Unit: Hartree
714- } // end deepks_scf == 1
715- else // deepks_scf == 0
716- {
717- const std::string file_obase = PARAM.globalv .global_out_dir + " deepks_obase.npy" ;
718- LCAO_deepks_io::save_matrix2npy (file_obase, o_tot, rank); // no scf, o_tot=o_base
719- } // end deepks_scf == 0
720- } // end deepks_out_labels == 1
721- } // end bandgap label
722-
723- if (PARAM.inp .deepks_bandgap == 4 )
724- {
725- int natom_H = 0 ;
726- for (int it = 0 ; it < ucell.ntype ; it++)
727- {
728- if (ucell.atoms [it].label == " H" )
729- {
730- natom_H = ucell.atoms [it].na ;
731- break ;
732- }
733- }
734- const int nocc = (PARAM.inp .nelec - natom_H) / 2 ;
735- ModuleBase::matrix o_tot (nks, 1 );
736- for (int iks = 0 ; iks < nks; ++iks)
737- {
738- // record band gap for each k point (including spin)
739- o_tot (iks, 0 ) = ekb (iks, nocc) - ekb (iks, nocc - 1 );
740- }
741-
742- const std::string file_otot
743- = PARAM.globalv .global_out_dir
744- + (PARAM.inp .deepks_out_labels == 1 ? " deepks_otot.npy" : " deepks_orbital.npy" );
745- LCAO_deepks_io::save_matrix2npy (file_otot, o_tot, rank); // Unit: Hartree
746-
747- if (PARAM.inp .deepks_out_labels == 1 ) // don't need these when deepks_out_labels == 2
748- {
749- if (PARAM.inp .deepks_scf )
750- {
751- ModuleBase::matrix wg_hl;
752- std::vector<TH> dm_bandgap;
753-
754- // Calculate O_delta
755- wg_hl.create (nks, PARAM.inp .nbands );
756- dm_bandgap.resize (nks);
757- wg_hl.zero_out ();
758- for (int iks = 0 ; iks < nks; ++iks)
759- {
760- wg_hl (iks, nocc - 1 ) = -1.0 ;
761- wg_hl (iks, nocc) = 1.0 ;
762- }
763- elecstate::cal_dm (ParaV, wg_hl, psi, dm_bandgap);
764-
765- ModuleBase::matrix o_delta (nks, 1 );
766-
767- // calculate and save orbital_precalc: [nks,NAt,NDscrpt]
768- torch::Tensor orbital_precalc;
769- DeePKS_domain::cal_orbital_precalc<TK, TH>(dm_bandgap,
770- lmaxd,
771- inlmax,
772- nat,
773- nks,
774- inl2l,
775- kvec_d,
776- phialpha,
777- gevdm,
778- inl_index,
779- ucell,
780- orb,
781- *ParaV,
782- GridD,
783- orbital_precalc);
784- DeePKS_domain::cal_o_delta<TK, TH>(dm_bandgap, *h_delta, o_delta, *ParaV, nks, nspin);
785-
786- // save obase and orbital_precalc
787- const std::string file_orbpre = PARAM.globalv .global_out_dir + " deepks_orbpre.npy" ;
788- LCAO_deepks_io::save_tensor2npy<double >(file_orbpre, orbital_precalc, rank);
789-
790- const std::string file_obase = PARAM.globalv .global_out_dir + " deepks_obase.npy" ;
791- LCAO_deepks_io::save_matrix2npy (file_obase, o_tot - o_delta, rank); // Unit: Hartree
792- } // end deepks_scf == 1
793- else // deepks_scf == 0
794- {
795- const std::string file_obase = PARAM.globalv .global_out_dir + " deepks_obase.npy" ;
796- LCAO_deepks_io::save_matrix2npy (file_obase, o_tot, rank); // no scf, o_tot=o_base
797- } // end deepks_scf == 0
798- } // end deepks_out_labels == 1
799- } // end bandgap label
800-
801539 // H(R) matrix part, for HR, base will not be calculated since they are HContainer objects
802540 if (PARAM.inp .deepks_v_delta < 0 )
803541 {
0 commit comments