| #ifndef GAIA_IO_FORMATS_HPP |
| #define GAIA_IO_FORMATS_HPP |
|
|
| #include <vector> |
| #include <string> |
| #include <fstream> |
| #include <map> |
| #include <iostream> |
|
|
| namespace gaia { |
| namespace io { |
|
|
| struct Molecule { |
| std::string name; |
| std::vector<double> coords; |
| std::map<std::string, double> properties; |
| }; |
|
|
| class FileIO { |
| public: |
| static bool write_sdf(const std::string& filename, const Molecule& mol) { |
| std::ofstream file(filename); |
| if (!file.is_open()) return false; |
| file << mol.name << "\n GAIA generated\n\n"; |
| file << " " << mol.coords.size()/3 << " 0 0 0 0 0 0 0 0 0 0 0\n"; |
| for (size_t i = 0; i < mol.coords.size(); i += 3) { |
| file << " " << mol.coords[i] << " " << mol.coords[i+1] |
| << " " << mol.coords[i+2] << " 0 0 0 0 0 0\n"; |
| } |
| file << "M END\n"; |
| file.close(); |
| return true; |
| } |
| |
| static bool write_jsonld(const std::string& filename, |
| const std::map<std::string, double>& scores) { |
| std::ofstream file(filename); |
| if (!file.is_open()) return false; |
| file << "{\n \"@context\": \"https://gaia.xyz/context.jsonld\",\n"; |
| file << " \"@type\": \"BindingScores\",\n \"scores\": {\n"; |
| int i = 0; |
| for (const auto& pair : scores) { |
| file << " \"" << pair.first << "\": " << pair.second; |
| if (i < (int)scores.size() - 1) file << ","; |
| file << "\n"; |
| i++; |
| } |
| file << " }\n}\n"; |
| file.close(); |
| return true; |
| } |
| }; |
|
|
| } |
| } |
|
|
| #endif |
|
|