| 273 | } |
| 274 | |
| 275 | std::vector<std::string> ScriptAPI::loadMoleculesFrom(const std::filesystem::path& path) { |
| 276 | if (!std::filesystem::exists(path)) { |
| 277 | throw std::runtime_error("molecule path does not exist: '" + path.string() + "'"); |
| 278 | } |
| 279 | |
| 280 | std::vector<std::filesystem::path> pdbFiles; |
| 281 | if (std::filesystem::is_regular_file(path)) { |
| 282 | if (lowercase(path.extension().string()) != ".pdb") { |
| 283 | throw std::runtime_error("molecule file must have .pdb extension: '" + path.string() + "'"); |
| 284 | } |
| 285 | pdbFiles.push_back(path); |
| 286 | } else if (std::filesystem::is_directory(path)) { |
| 287 | for (const std::filesystem::directory_entry& entry : std::filesystem::directory_iterator(path)) { |
| 288 | if (!entry.is_regular_file()) { |
| 289 | continue; |
| 290 | } |
| 291 | if (lowercase(entry.path().extension().string()) != ".pdb") { |
| 292 | continue; |
| 293 | } |
| 294 | pdbFiles.push_back(entry.path()); |
| 295 | } |
| 296 | } else { |
| 297 | throw std::runtime_error("molecule path must be a .pdb file or directory: '" + path.string() + "'"); |
| 298 | } |
| 299 | |
| 300 | std::sort(pdbFiles.begin(), pdbFiles.end()); |
| 301 | |
| 302 | std::vector<std::string> loadedNames; |
| 303 | loadedNames.reserve(pdbFiles.size()); |
| 304 | for (const std::filesystem::path& pdbPath : pdbFiles) { |
| 305 | const std::string moleculeName = pdbPath.stem().string(); |
| 306 | if (moleculeName.empty()) { |
| 307 | continue; |
| 308 | } |
| 309 | |
| 310 | simulation_.loadMoleculeTemplate(moleculeName, pdbPath); |
| 311 | loadedNames.push_back(moleculeName); |
| 312 | } |
| 313 | |
| 314 | return loadedNames; |
| 315 | } |
| 316 | |
| 317 | } // namespace Lattice |
nothing calls this directly
no test coverage detected