Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F82132430
database.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Sep 9, 18:37
Size
2 KB
Mime Type
text/x-c
Expires
Wed, Sep 11, 18:37 (2 d)
Engine
blob
Format
Raw Data
Handle
20657297
Attached To
rSPECMICP SpecMiCP / ReactMiCP
database.cpp
View Options
/*-------------------------------------------------------
- Module : database
- File : database.cpp
- Author : Fabien Georget
Copyright (c) 2014, Fabien Georget, Princeton University
---------------------------------------------------------*/
#include "database.hpp"
#include <iostream>
#include "selector.hpp"
#include "canonicalizer.hpp"
#include "switch_basis.hpp"
#include "mineral_selector.hpp"
#include "reader.hpp"
namespace specmicp {
namespace database {
void Database::make_canonical()
{
canonicalize_database(data);
}
void Database::change_basis(std::vector<int>& new_basis)
{
BasisSwitcher(data).change_basis(new_basis);
}
// this is a proxy to a DatabaseSelector
void Database::remove_components(const std::vector<int>& id_components_to_remove)
{
DatabaseSelector selector(data);
selector.remove_component(id_components_to_remove);
}
// this is a proxy to a DatabaseSelector
void Database::keep_only_components(const std::vector<int>& id_components_to_keep)
{
DatabaseSelector selector(data);
selector.keep_only_component(id_components_to_keep);
}
void Database::minerals_keep_only(const std::vector<std::string>& minerals_to_keep)
{
MineralSelector(data).keep_only(minerals_to_keep);
}
void Database::swap_components(std::map<std::string, std::string>& swap_to_make)
{
std::vector<int> id_swap;
id_swap.reserve(data->nb_component);
for (int i=0; i<data->nb_component; ++i)
{
id_swap.push_back(i);
}
for (auto it=swap_to_make.begin(); it!=swap_to_make.end(); ++it)
{
if (it->first == "H2O") {
throw std::invalid_argument("Basis switch : water cannot be swapped from basis");
}
const int idc = safe_label_to_id(it->first, data->labels_basis);
const int idaq = data->nb_component + label_to_id(it->second, data->labels_aqueous);
id_swap[idc] = idaq;
}
change_basis(id_swap);
}
void Database::parse_database(std::string filepath)
{
DataReader reader(filepath);
reader.parse();
set_database(reader.get_database());
}
} // end namespace database
} // end namespace specmicp
Event Timeline
Log In to Comment