-
Notifications
You must be signed in to change notification settings - Fork 19
feat: CIF handling #2339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RobBuchananCompPhys
wants to merge
4
commits into
develop2
Choose a base branch
from
dissolve2/cif-handling
base: develop2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: CIF handling #2339
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Copyright (c) 2026 Team Dissolve and contributors | ||
|
|
||
| #include "nodes/cifBondingOptions.h" | ||
|
|
||
| CIFBondingOptionsNode::CIFBondingOptionsNode(Graph *parentGraph) : Node(parentGraph) | ||
| { | ||
| // Inputs | ||
| addInput<CIFLoaderNode::CIFContext *>("CIFContext", "CIF handling context derived from parsing of CIF file", context_) | ||
| ->setFlags({ParameterBase::Required}); | ||
|
|
||
| // Outputs | ||
| addOutput<CIFLoaderNode::CIFContext *>("CIFContext", "CIF handling context derived from parsing of CIF file", context_); | ||
|
|
||
| // Options | ||
| addOption<Number>("BondingTolerance", "Bonding tolerance, if calculating bonding rather than using CIF definitions", | ||
| bondingTolerance_); | ||
| addOption<bool>("UseCIFBondingDefinitions", "Whether to use CIF bonding definitions", useCIFBondingDefinitions_); | ||
| addOption<bool>("PreventMetallicBonds", "Whether to prevent metallic bonding", preventMetallicBonds_); | ||
| } | ||
|
|
||
| std::string_view CIFBondingOptionsNode::type() const { return "CIFBondingOptions"; } | ||
|
|
||
| std::string_view CIFBondingOptionsNode::summary() const { return "Apply bonding options to a CIF context"; } | ||
|
|
||
| // Run main processing | ||
| NodeConstants::ProcessResult CIFBondingOptionsNode::process() | ||
| { | ||
|
|
||
| context_->setBondingTolerance(bondingTolerance_.asDouble()); | ||
| context_->setUseCIFBondingDefinitions(useCIFBondingDefinitions_); | ||
| context_->setPreventMetallicBonds(preventMetallicBonds_); | ||
|
|
||
| return NodeConstants::ProcessResult::Success; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Copyright (c) 2026 Team Dissolve and contributors | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "nodes/cifLoader.h" | ||
| #include "nodes/node.h" | ||
|
|
||
| // CIFLoader Node | ||
| class CIFBondingOptionsNode : public Node | ||
| { | ||
| public: | ||
| CIFBondingOptionsNode(Graph *parentGraph); | ||
| ~CIFBondingOptionsNode() override = default; | ||
|
|
||
| public: | ||
| std::string_view type() const override; | ||
| std::string_view summary() const override; | ||
|
|
||
| /* | ||
| * Definition | ||
| */ | ||
| private: | ||
| // CIF handler context | ||
| CIFLoaderNode::CIFContext *context_{nullptr}; | ||
| // Bonding tolerance, if calculating bonding rather than using CIF definitions | ||
| Number bondingTolerance_{1.1}; | ||
| // Whether to use CIF bonding definitions | ||
| bool useCIFBondingDefinitions_{false}; | ||
| // Whether to prevent metallic bonding | ||
| bool preventMetallicBonds_{true}; | ||
|
|
||
| /* | ||
| * Processing | ||
| */ | ||
| private: | ||
| // Run main processing | ||
| NodeConstants::ProcessResult process() override; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Copyright (c) 2026 Team Dissolve and contributors | ||
|
|
||
| #include "nodes/cifConfiguration.h" | ||
| #include <algorithm> | ||
| #include <iterator> | ||
|
|
||
| CIFConfigurationNode::CIFConfigurationNode(Graph *parentGraph) : Node(parentGraph) | ||
| { | ||
| // Inputs | ||
| addInput<CIFLoaderNode::CIFContext *>("CIFContext", "CIF handling context derived from parsing of CIF file", context_) | ||
| ->setFlags({ParameterBase::Required}); | ||
|
|
||
| // Outputs | ||
| addOutput<const Species *>("UnitCellSpecies", "Cleaned unit cell", unitCellSpecies_); | ||
| addOutput<const Species *>("SuperCellSpecies", "Supercell species", supercellSpecies_); | ||
| addOutput<std::vector<CIFMolecularSpecies>>("MolecularSpecies", "Detected molecular species", molecularSpecies_); | ||
| addOutput<Configuration *>("SuperCellConfiguration", "Supercell configuration pointer", supercellConfiguration_); | ||
|
|
||
| // Options | ||
| addOption<Vector3i>("SuperCellRepeat", "Supercell repeat", supercellRepeat_); | ||
| } | ||
|
|
||
| std::string_view CIFConfigurationNode::type() const { return "CIFConfiguration"; } | ||
|
|
||
| std::string_view CIFConfigurationNode::summary() const { return "Generate a supercell configuration from a CIF context"; } | ||
|
|
||
| // Run main processing | ||
| NodeConstants::ProcessResult CIFConfigurationNode::process() | ||
| { | ||
|
|
||
| // Generate from CIF context | ||
| context_->setSupercellRepeat(supercellRepeat_); | ||
| context_->generate(); | ||
|
|
||
| // Get supercell configuration | ||
| supercellConfiguration_ = context_->generatedConfiguration(); | ||
|
|
||
| // Get cleaned unit cell species | ||
| unitCellSpecies_ = &(context_->cleanedUnitCellSpecies()); | ||
|
|
||
| // Get supercell species | ||
| supercellSpecies_ = &(context_->supercellSpecies()); | ||
|
|
||
| // Get detected molecular species | ||
| auto &cifMols = context_->molecularSpecies(); | ||
| molecularSpecies_.clear(); | ||
| std::copy(cifMols.begin(), cifMols.end(), std::back_inserter(molecularSpecies_)); | ||
|
|
||
| return NodeConstants::ProcessResult::Success; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Copyright (c) 2026 Team Dissolve and contributors | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "nodes/cifLoader.h" | ||
| #include "nodes/node.h" | ||
|
|
||
| // CIFLoader Node | ||
| class CIFConfigurationNode : public Node | ||
| { | ||
| public: | ||
| CIFConfigurationNode(Graph *parentGraph); | ||
| ~CIFConfigurationNode() override = default; | ||
|
|
||
| public: | ||
| std::string_view type() const override; | ||
| std::string_view summary() const override; | ||
|
|
||
| /* | ||
| * Definition | ||
| */ | ||
| private: | ||
| // CIF handler context | ||
| CIFLoaderNode::CIFContext *context_{nullptr}; | ||
| // Supercell configuration | ||
| Configuration *supercellConfiguration_{nullptr}; | ||
| // Unit cell species | ||
| const Species *unitCellSpecies_{nullptr}; | ||
| // Supercell species | ||
| const Species *supercellSpecies_{nullptr}; | ||
| // Detected molecular species | ||
| std::vector<CIFMolecularSpecies> molecularSpecies_; | ||
| // Supercell repeat | ||
| Vector3i supercellRepeat_{1, 1, 1}; | ||
|
|
||
| /* | ||
| * Processing | ||
| */ | ||
| private: | ||
| // Run main processing | ||
| NodeConstants::ProcessResult process() override; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Copyright (c) 2026 Team Dissolve and contributors | ||
|
|
||
| #include "nodes/cifLoader.h" | ||
| #include <sstream> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| CIFLoaderNode::CIFLoaderNode(Graph *parentGraph) : Node(parentGraph) | ||
| { | ||
| // Outputs | ||
| addPointerOutput<CIFContext>("CIFContext", "CIF handling context derived from parsing of CIF file", context_) | ||
| ->setFlags({ParameterBase::Required}); | ||
|
|
||
| // Option | ||
| addOption<std::string>("FilePath", "File path", filePath_); | ||
| addOption<SpaceGroups::SpaceGroupId>("SpaceGroupID", "Set space group from index", spaceGroup_); | ||
| } | ||
|
|
||
| std::string_view CIFLoaderNode::type() const { return "CIFLoader"; } | ||
|
|
||
| std::string_view CIFLoaderNode::summary() const | ||
| { | ||
| return "Load a CIF file and apply contained crystallographic data to a target configuration"; | ||
| } | ||
|
|
||
| // Run main processing | ||
| NodeConstants::ProcessResult CIFLoaderNode::process() | ||
| { | ||
| // Read contents of CIF file | ||
| if (context_.read(filePath_)) | ||
| { | ||
| if (spaceGroup_ != SpaceGroups::NoSpaceGroup) | ||
| context_.setSpaceGroup(spaceGroup_); | ||
| return NodeConstants::ProcessResult::Success; | ||
| } | ||
|
|
||
| error("Failed to read contents of CIF file"); | ||
|
|
||
| return NodeConstants::ProcessResult::Failed; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Copyright (c) 2026 Team Dissolve and contributors | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "io/import/cif.h" | ||
| #include "nodes/node.h" | ||
|
|
||
| // CIFLoader Node | ||
| class CIFLoaderNode : public Node | ||
| { | ||
| public: | ||
| using CIFContext = CIFHandler; | ||
|
|
||
| public: | ||
| CIFLoaderNode(Graph *parentGraph); | ||
| ~CIFLoaderNode() override = default; | ||
|
|
||
| public: | ||
| std::string_view type() const override; | ||
| std::string_view summary() const override; | ||
|
|
||
| /* | ||
| * Definition | ||
| */ | ||
| private: | ||
| // CIF handler context | ||
| CIFContext context_; | ||
| // Space group ID | ||
| SpaceGroups::SpaceGroupId spaceGroup_{SpaceGroups::SpaceGroupId::NoSpaceGroup}; | ||
| // CIF filepath | ||
| std::string filePath_; | ||
|
|
||
| /* | ||
| * Processing | ||
| */ | ||
| private: | ||
| // Run main processing | ||
| NodeConstants::ProcessResult process() override; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Copyright (c) 2026 Team Dissolve and contributors | ||
|
|
||
| #include "nodes/cifMolecularSpecies.h" | ||
| #include <algorithm> | ||
| #include <iterator> | ||
|
|
||
| CIFMolecularSpeciesNode::CIFMolecularSpeciesNode(Graph *parentGraph) : Node(parentGraph) | ||
| { | ||
| // Inputs | ||
| addInput<CIFLoaderNode::CIFContext *>("CIFContext", "CIF handling context derived from parsing of CIF file", context_) | ||
| ->setFlags({ParameterBase::Required}); | ||
|
|
||
| // Outputs | ||
| addOutput<std::vector<CIFMolecularSpecies>>("DetectedMolecularSpecies", "Detected molecular species", molecularSpecies_); | ||
| addOutput<Configuration *>("SuperCellConfiguration", "Supercell configuration pointer", supercellConfiguration_); | ||
|
|
||
| // Options | ||
| addOption<Vector3i>("SuperCellRepeat", "Supercell repeat", supercellRepeat_); | ||
| } | ||
|
|
||
| std::string_view CIFMolecularSpeciesNode::type() const { return "CIFMolecularSpecies"; } | ||
|
|
||
| std::string_view CIFMolecularSpeciesNode::summary() const | ||
| { | ||
| return "Output a configuration containing individual molecules based on detected species"; | ||
| } | ||
|
|
||
| // Run main processing | ||
| NodeConstants::ProcessResult CIFMolecularSpeciesNode::process() | ||
| { | ||
| // Generate from CIF context | ||
| context_->setSupercellRepeat(supercellRepeat_); | ||
| context_->generate(); | ||
|
|
||
| // Get supercell configuration | ||
| supercellConfiguration_ = context_->generatedConfiguration(); | ||
| supercellConfiguration_->setName(context_->chemicalFormula()); | ||
|
|
||
| // Get detected molecular species | ||
| auto &cifMols = context_->molecularSpecies(); | ||
| molecularSpecies_.clear(); | ||
| std::copy(cifMols.begin(), cifMols.end(), std::back_inserter(molecularSpecies_)); | ||
|
|
||
| return NodeConstants::ProcessResult::Success; | ||
| } | ||
|
|
||
| // Get cleaned unit cell species | ||
| const Species &CIFMolecularSpeciesNode::cleanedUnitCellSpecies() const { return context_->cleanedUnitCellSpecies(); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Copyright (c) 2026 Team Dissolve and contributors | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "nodes/cifLoader.h" | ||
| #include "nodes/node.h" | ||
|
|
||
| // CIFLoader Node | ||
| class CIFMolecularSpeciesNode : public Node | ||
| { | ||
| public: | ||
| CIFMolecularSpeciesNode(Graph *parentGraph); | ||
| ~CIFMolecularSpeciesNode() override = default; | ||
|
|
||
| public: | ||
| std::string_view type() const override; | ||
| std::string_view summary() const override; | ||
|
|
||
| /* | ||
| * Definition | ||
| */ | ||
| private: | ||
| // CIF handler context | ||
| CIFLoaderNode::CIFContext *context_{nullptr}; | ||
| // Supercell configuration | ||
| Configuration *supercellConfiguration_{nullptr}; | ||
| // Detected molecular species | ||
| std::vector<CIFMolecularSpecies> molecularSpecies_; | ||
| // Supercell repeat | ||
| Vector3i supercellRepeat_{1, 1, 1}; | ||
|
|
||
| /* | ||
| * Processing | ||
| */ | ||
| private: | ||
| // Run main processing | ||
| NodeConstants::ProcessResult process() override; | ||
|
|
||
| /* | ||
| * Getters | ||
| */ | ||
| public: | ||
| // Get cleaned unit cell species | ||
| const Species &cleanedUnitCellSpecies() const; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As briefly discussed, it is probably worth having a separate
Configuration-maker node for each type of crystal cell we're generating (supercell, non-periodic, full species etc.).