Skip to content

Commit

Permalink
Merge branch 'move_species_to_ionic' into 'master'
Browse files Browse the repository at this point in the history
Move species to ionic

See merge request npneq/inq!1099
  • Loading branch information
xavierandrade committed Jul 2, 2024
2 parents a3e4a22 + 83bce90 commit 4232b98
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/hamiltonian/atomic_potential.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace hamiltonian {
return nel;
}

auto & pseudo_for_element(input::species const & el) const {
auto & pseudo_for_element(ionic::species const & el) const {
return pseudopotential_list_.at(el.symbol());
}

Expand Down Expand Up @@ -332,7 +332,7 @@ TEST_CASE(INQ_TEST_FILE, INQ_TEST_TAG){
using namespace inq::magnitude;
using namespace Catch::literals;
using Catch::Approx;
using input::species;
using ionic::species;

double const gcut = 0.785;

Expand Down
4 changes: 2 additions & 2 deletions src/interface/ions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ These are the uses for the command:
status();
}

static void insert(input::species const & sp, vector3<quantity<magnitude::length>> const & pos) {
static void insert(ionic::species const & sp, vector3<quantity<magnitude::length>> const & pos) {
auto ions = systems::ions::load(".inq/default_ions");
ions.insert(sp, pos);
ions.save(input::environment::global().comm(), ".inq/default_ions");
}

static void insert_fractional(input::species const & sp, vector3<double, contravariant> const & pos) {
static void insert_fractional(ionic::species const & sp, vector3<double, contravariant> const & pos) {
auto ions = systems::ions::load(".inq/default_ions");
ions.insert_fractional(sp, pos);
ions.save(input::environment::global().comm(), ".inq/default_ions");
Expand Down
26 changes: 10 additions & 16 deletions src/input/species.hpp → src/ionic/species.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -*- indent-tabs-mode: t -*- */

#ifndef INPUT__SPECIES
#define INPUT__SPECIES
#ifndef IONIC__SPECIES
#define IONIC__SPECIES

// Copyright (C) 2019-2023 Lawrence Livermore National Security, LLC., Xavier Andrade, Alfredo A. Correa
//
Expand All @@ -16,7 +16,7 @@
#include <optional>

namespace inq {
namespace input {
namespace ionic {

class species : public pseudo::element {

Expand Down Expand Up @@ -90,21 +90,15 @@ class species : public pseudo::element {
auto filter_pseudo() const {
return filter_.value_or(true);
}

template<class OStream>
friend OStream & operator<<(OStream & out, species const & self){
out << self.symbol();
return out;
}

};

}
}
#endif

#ifdef INQ_INPUT_SPECIES_UNIT_TEST
#undef INQ_INPUT_SPECIES_UNIT_TEST
#ifdef INQ_IONIC_SPECIES_UNIT_TEST
#undef INQ_IONIC_SPECIES_UNIT_TEST

#include <catch2/catch_all.hpp>

Expand All @@ -115,15 +109,15 @@ TEST_CASE(INQ_TEST_FILE, INQ_TEST_TAG) {

SECTION("Constructor"){

auto s = input::species("Xe");
auto s = ionic::species("Xe");

CHECK(s.atomic_number() == 54);
CHECK(not s.has_file());
}

SECTION("Constructor with options"){

auto s = input::species("Xe").mass(20);
auto s = ionic::species("Xe").mass(20);

CHECK(s.atomic_number() == 54);
CHECK(not s.has_file());
Expand All @@ -132,23 +126,23 @@ TEST_CASE(INQ_TEST_FILE, INQ_TEST_TAG) {

SECTION("Option mass"){

auto s = input::species("U").mass(235);
auto s = ionic::species("U").mass(235);

CHECK(s.symbol() == "U");
CHECK(s.mass() == 428378.7975_a);
}

SECTION("Option symbol"){

auto s = input::species("U").symbol("U235").mass(235);
auto s = ionic::species("U").symbol("U235").mass(235);

CHECK(s.symbol() == "U235");
CHECK(s.mass() == 428378.7975_a);
}

SECTION("Option pseudopotential"){

auto s = input::species("He").pseudo("hola");
auto s = ionic::species("He").pseudo("hola");

CHECK(s.symbol() == "He");
CHECK(s.has_file());
Expand Down
6 changes: 3 additions & 3 deletions src/ionic/species_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#include <input/species.hpp>
#include <ionic/species.hpp>

namespace inq {
namespace ionic {

class species_set {

using container_type = std::unordered_map<std::string, input::species>;
using container_type = std::unordered_map<std::string, ionic::species>;

container_type list_;

Expand All @@ -30,7 +30,7 @@ class species_set {
return list_;
}

auto insert(input::species const & sp) {
auto insert(ionic::species const & sp) {
list_.insert_or_assign(sp.symbol(), sp);
}

Expand Down
4 changes: 2 additions & 2 deletions src/parse/cif.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <gemmi/symmetry.hpp>
#include <vector>

#include <input/species.hpp>
#include <ionic/species.hpp>
#include <magnitude/length.hpp>
#include <math/vector3.hpp>

Expand All @@ -24,7 +24,7 @@ namespace parse {
class cif {

std::vector<vector3<double>> lattice_vectors_;
std::vector<input::species> atoms_;
std::vector<ionic::species> atoms_;
std::vector<vector3<double, contravariant>> positions_;

static auto to_double(std::string const * strptr, std::string const & cif_file_name){
Expand Down
10 changes: 5 additions & 5 deletions src/parse/poscar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <math/vector3.hpp>

#include <pseudopod/element.hpp>
#include <input/species.hpp>
#include <ionic/species.hpp>
#include <magnitude/length.hpp>
#include <magnitude/time.hpp>

Expand All @@ -29,7 +29,7 @@ namespace parse {
class poscar {

std::vector<vector3<double>> lattice_vectors_;
std::vector<input::species> atoms_;
std::vector<ionic::species> atoms_;
std::vector<vector3<double>> positions_;
std::vector<vector3<double>> velocities_;

Expand Down Expand Up @@ -81,7 +81,7 @@ class poscar {
iss >> species_name;
if(iss.eof()) break;
species.push_back(species_name);
input::species sp(species.back());
ionic::species sp(species.back());
if(not sp.valid()) throw std::runtime_error("Cannot read the species from POSCAR file \'" + poscar_file_name +
"\'. Make sure your file contains the optional \'Species names\' line (see\n https://www.vasp.at/wiki/index.php/POSCAR for details).");
}
Expand All @@ -104,7 +104,7 @@ class poscar {
for(int iatom = 0; iatom < species_num[ispecies]; iatom++){
vector3<double> pos;
poscar_file >> pos;
atoms_.emplace_back(input::species(species[ispecies]));
atoms_.emplace_back(ionic::species(species[ispecies]));
positions_.emplace_back(scaling_factor*in_atomic_units(1.0_A*pos));
std::getline(poscar_file, tail);
}
Expand All @@ -117,7 +117,7 @@ class poscar {
for(int iatom = 0; iatom < species_num[ispecies]; iatom++){
vector3<double, contravariant> pos;
poscar_file >> pos;
atoms_.emplace_back(input::species(species[ispecies]));
atoms_.emplace_back(ionic::species(species[ispecies]));
positions_.emplace_back(cell.metric().to_cartesian(pos));
std::getline(poscar_file, tail);
}
Expand Down
4 changes: 2 additions & 2 deletions src/parse/xyz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
#include <math/vector3.hpp>

#include <pseudopod/element.hpp>
#include <input/species.hpp>
#include <ionic/species.hpp>
#include <magnitude/length.hpp>

namespace inq {
namespace parse {

class xyz {

std::vector<input::species> atoms_;
std::vector<ionic::species> atoms_;
std::vector<vector3<double>> positions_;

public:
Expand Down
16 changes: 8 additions & 8 deletions src/systems/ions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <spglib.h>

#include <systems/cell.hpp>
#include <input/species.hpp>
#include <ionic/species.hpp>
#include <ionic/species_set.hpp>
#include <gpu/array.hpp>
#include <parse/cif.hpp>
Expand Down Expand Up @@ -42,7 +42,7 @@ class ions {
ionic::species_set species_list_;

template <typename PositionType>
void add_atom(input::species const & element, PositionType const & position, vector3<double> const & vel = vector3<double>(0.0, 0.0, 0.0)){
void add_atom(ionic::species const & element, PositionType const & position, vector3<double> const & vel = vector3<double>(0.0, 0.0, 0.0)){
atoms_.push_back(element.symbol());
positions_.push_back(in_atomic_units(position));
velocities_.push_back(vel);
Expand Down Expand Up @@ -220,11 +220,11 @@ class ions {
return cell_;
}

void insert(input::species const & sp, vector3<quantity<magnitude::length>> const & pos){
void insert(ionic::species const & sp, vector3<quantity<magnitude::length>> const & pos){
add_atom(sp, pos);
}

void insert_fractional(input::species const & sp, vector3<double, contravariant> const & pos){
void insert_fractional(ionic::species const & sp, vector3<double, contravariant> const & pos){
add_atom(sp, cell_.metric().to_cartesian(pos));
}

Expand Down Expand Up @@ -345,7 +345,7 @@ TEST_CASE(INQ_TEST_FILE, INQ_TEST_TAG) {

CHECK(ions.size() == 1);
CHECK(ions.species(0).atomic_number() == 54);
CHECK(ions.species(0) == input::species(54));
CHECK(ions.species(0) == ionic::species(54));
CHECK(ions.species(0).charge() == -54.0_a);
CHECK(ions.species(0).mass() == 239333.5935636_a);
CHECK(ions.positions()[0][0] == 1000.0_a);
Expand Down Expand Up @@ -402,7 +402,7 @@ TEST_CASE(INQ_TEST_FILE, INQ_TEST_TAG) {

CHECK(ions.size() == 13);
CHECK(ions.species(12).atomic_number() == 17);
CHECK(ions.species(12) == input::species(17));
CHECK(ions.species(12) == ionic::species(17));
CHECK(ions.species(12).charge() == -17.0_a);
CHECK(ions.species(12).mass() == 64614.105771_a);
CHECK(ions.positions()[12][0] == -3.0_a);
Expand Down Expand Up @@ -448,7 +448,7 @@ TEST_CASE(INQ_TEST_FILE, INQ_TEST_TAG) {
CHECK(read_ions.velocities()[11][2] == 0.0_a);

CHECK(read_ions.species(12).atomic_number() == 17);
CHECK(read_ions.species(12) == input::species(17));
CHECK(read_ions.species(12) == ionic::species(17));
CHECK(read_ions.species(12).charge() == -17.0_a);
CHECK(read_ions.species(12).mass() == 64614.105771_a);
CHECK(read_ions.positions()[12][0] == -3.0_a);
Expand Down Expand Up @@ -506,7 +506,7 @@ TEST_CASE(INQ_TEST_FILE, INQ_TEST_TAG) {

CHECK(ions.size() == 13);
CHECK(ions.species(12).atomic_number() == 17);
CHECK(ions.species(12) == input::species(17));
CHECK(ions.species(12) == ionic::species(17));
CHECK(ions.species(12).charge() == -17.0_a);
CHECK(ions.species(12).mass() == 64614.105771_a);
CHECK(ions.positions()[12][0] == -3.0_a);
Expand Down
2 changes: 1 addition & 1 deletion tests/bo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int main(int argc, char ** argv){
//SINGLE ATOM SANITY CHECK
{
systems::ions ions(systems::cell::cubic(8.0_b).finite());
ions.insert(input::species("He").nofilter(), {0.0_b, 0.0_b, 0.0_b});
ions.insert(ionic::species("He").nofilter(), {0.0_b, 0.0_b, 0.0_b});

systems::electrons electrons(ions, options::electrons{}.extra_states(3).cutoff(30.0_Ha));
ground_state::initial_guess(ions, electrons);
Expand Down
2 changes: 1 addition & 1 deletion tests/hydrogen_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, char ** argv){

inq::utils::match energy_match(3.0e-5);

auto local_h = inq::input::species("H").symbol("Hloc").pseudo(inq::config::path::unit_tests_data() + "H.blyp-vbc.UPF");
auto local_h = inq::ionic::species("H").symbol("Hloc").pseudo(inq::config::path::unit_tests_data() + "H.blyp-vbc.UPF");

inq::systems::ions ions(inq::systems::cell::cubic(15.0_b).finite());
ions.insert(local_h, {150.0_b, -30.0_b, 0.0_b});
Expand Down
4 changes: 2 additions & 2 deletions tests/pseudos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main(int argc, char ** argv){
{
systems::ions ions(cell);

ions.insert(input::species("C").pseudo(inq::config::path::unit_tests_data() + "C_ONCV_PBE-1.2.xml"), {0.0_b, 0.0_b, 0.0_b});
ions.insert(ionic::species("C").pseudo(inq::config::path::unit_tests_data() + "C_ONCV_PBE-1.2.xml"), {0.0_b, 0.0_b, 0.0_b});

systems::electrons electrons(ions, options::electrons{}.cutoff(25.0_Ha).extra_states(4).temperature(300.0_K));

Expand All @@ -44,7 +44,7 @@ int main(int argc, char ** argv){
{
systems::ions ions(cell);

ions.insert(input::species("C"), {0.0_b, 0.0_b, 0.0_b});
ions.insert(ionic::species("C"), {0.0_b, 0.0_b, 0.0_b});

systems::electrons electrons(ions, options::electrons{}.pseudopotentials(pseudo::set::ccecp()).cutoff(25.0_Ha).extra_states(4).temperature(300.0_K));

Expand Down

0 comments on commit 4232b98

Please sign in to comment.