|
| 1 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | +// Copyright (c) 2026 Team Dissolve and contributors |
| 3 | + |
| 4 | +#include "nodes/importConfigurationTrajectory.h" |
| 5 | + |
| 6 | +ImportConfigurationTrajectoryNode::ImportConfigurationTrajectoryNode(Graph *parentGraph) : Node(parentGraph) |
| 7 | +{ |
| 8 | + // Inputs |
| 9 | + addInput<Configuration *>("Configuration", "Configuration to which Trajectory will be imported", configuration_); |
| 10 | + |
| 11 | + // Options |
| 12 | + addOption<std::string>("FilePath", "File path", filePath_); |
| 13 | + addOption<TrajectoryImportFileFormat::TrajectoryImportFormat>("FileFormat", "File format", format_); |
| 14 | + |
| 15 | + // Outputs |
| 16 | + addOutput<Configuration *>("Configuration", "Output configuration", configuration_); |
| 17 | + |
| 18 | + // Serialisable data |
| 19 | + addSerialisable("filePosition", filePosition_); |
| 20 | +} |
| 21 | + |
| 22 | +std::string_view ImportConfigurationTrajectoryNode::type() const { return "ImportTrajectory"; } |
| 23 | + |
| 24 | +std::string_view ImportConfigurationTrajectoryNode::summary() const |
| 25 | +{ |
| 26 | + return "Import configuration coordinates from sequential frames of a trajectory."; |
| 27 | +} |
| 28 | + |
| 29 | +NodeConstants::ProcessResult ImportConfigurationTrajectoryNode::process() |
| 30 | +{ |
| 31 | + TrajectoryImportFileFormat format(filePath_, format_); |
| 32 | + |
| 33 | + message("Import: Reading trajectory file frame from '{}' into Configuration '{}'...\n", format.filename(), |
| 34 | + configuration_->name()); |
| 35 | + |
| 36 | + // Open the file |
| 37 | + LineParser parser; |
| 38 | + if ((!parser.openInput(format.filename())) || (!parser.isFileGoodForReading())) |
| 39 | + { |
| 40 | + error("Couldn't open trajectory file '{}'.\n", format.filename()); |
| 41 | + return NodeConstants::ProcessResult::Failed; |
| 42 | + } |
| 43 | + |
| 44 | + // Seek to the next file position |
| 45 | + parser.seekg(filePosition_); |
| 46 | + |
| 47 | + // Read the frame |
| 48 | + std::optional<Matrix3> unitCell; |
| 49 | + if (!format.importData(parser, configuration_, unitCell)) |
| 50 | + { |
| 51 | + error("Failed to read trajectory frame data.\n"); |
| 52 | + return NodeConstants::ProcessResult::Failed; |
| 53 | + } |
| 54 | + |
| 55 | + configuration_->notifyAtomicPositionsChanged(); |
| 56 | + |
| 57 | + // Store the new trajectory file position |
| 58 | + filePosition_ = parser.tellg(); |
| 59 | + |
| 60 | + // Set the unit cell if one was read in |
| 61 | + if (unitCell) |
| 62 | + configuration_->createBox(unitCell.value()); |
| 63 | + |
| 64 | + return NodeConstants::ProcessResult::Success; |
| 65 | +} |
0 commit comments