-
Notifications
You must be signed in to change notification settings - Fork 0
Xyz to mol #3
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
Merged
Merged
Xyz to mol #3
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3232f28
started inital xyz_to_mol addition
jlheflin d2cb93b
initial commit for xyz_to_mol functionality
jlheflin 5c54e60
removed xyz file in src
jlheflin 1e52296
Committing clang-format changes
github-actions[bot] 603555b
switched up xyz_to_mol.cpp test
jlheflin fbfc280
was probably builder error, forgot to set to build shared libs
jlheflin 2d45e17
made test build its own xyz file
jlheflin d5bf1ef
made src file close input file, adjusted tests
jlheflin 746a7cf
changed test to a string comparison
jlheflin 4487b6e
added assertion for nuclei
jlheflin f473726
made requested changes
jlheflin 7a69cfb
reverted src xyz_to_mol
jlheflin 2b0286e
added pseudo modules for tests
jlheflin 6e29bcd
lambda'd the test modules
jlheflin 1987115
added exception for mising file
jlheflin 39f4cfd
reconstructed operator== for molecules for verbosity
jlheflin c572ba7
fixed incorrect mass
jlheflin 3d4fa76
made suggested changes
jlheflin 1b4e9dd
make suggested changes to src and test files
jlheflin 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
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,110 @@ | ||
| # Copyright 2022 NWChemEx-Project | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| --- | ||
| Language: Cpp | ||
| # BasedOnStyle: Mozilla | ||
| AccessModifierOffset: -4 | ||
| AlignAfterOpenBracket: Align | ||
| AlignConsecutiveAssignments: true | ||
| AlignConsecutiveDeclarations: false | ||
| AlignEscapedNewlines: Left | ||
| AlignOperands: true | ||
| AlignTrailingComments: true | ||
| AllowAllParametersOfDeclarationOnNextLine: true | ||
| AllowShortBlocksOnASingleLine: true | ||
| AllowShortCaseLabelsOnASingleLine: true | ||
| AllowShortFunctionsOnASingleLine: All | ||
| AllowShortIfStatementsOnASingleLine: true | ||
| AllowShortLoopsOnASingleLine: true | ||
| AlwaysBreakAfterDefinitionReturnType: false | ||
| AlwaysBreakAfterReturnType: None | ||
| AlwaysBreakBeforeMultilineStrings: false | ||
| AlwaysBreakTemplateDeclarations: true | ||
| BinPackArguments: true | ||
| BinPackParameters: true | ||
| BraceWrapping: | ||
| AfterClass: false | ||
| AfterControlStatement: false | ||
| AfterEnum: false | ||
| AfterFunction: false | ||
| AfterNamespace: false | ||
| AfterObjCDeclaration: false | ||
| AfterStruct: false | ||
| AfterUnion: false | ||
| BeforeCatch: false | ||
| BeforeElse: false | ||
| IndentBraces: false | ||
| BreakAfterJavaFieldAnnotations: false | ||
| BreakBeforeBinaryOperators: None | ||
| BreakBeforeBraces: Custom | ||
| BreakBeforeInheritanceComma: false | ||
| BreakBeforeTernaryOperators: false | ||
| BreakConstructorInitializers: AfterColon | ||
| BreakStringLiterals: true | ||
| ColumnLimit: 80 | ||
| CommentPragmas: '^ IWYU pragma:' | ||
| CompactNamespaces: false | ||
| ConstructorInitializerAllOnOneLineOrOnePerLine: true | ||
| ConstructorInitializerIndentWidth: 2 | ||
| ContinuationIndentWidth: 2 | ||
| Cpp11BracedListStyle: true | ||
| DerivePointerAlignment: false | ||
| DisableFormat: false | ||
| ExperimentalAutoDetectBinPacking: false | ||
| FixNamespaceComments: true | ||
| ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] | ||
| IncludeCategories: | ||
| - Regex: '^"' | ||
| Priority: 1 | ||
| - Regex: '^<' | ||
| Priority: 2 | ||
| IncludeIsMainRegex: '(Test)$' | ||
| IndentCaseLabels: true | ||
| IndentWidth: 4 | ||
| IndentWrappedFunctionNames: false | ||
| JavaScriptQuotes: Leave | ||
| JavaScriptWrapImports: true | ||
| KeepEmptyLinesAtTheStartOfBlocks: false | ||
| MacroBlockBegin: '' | ||
| MacroBlockEnd: '' | ||
| MaxEmptyLinesToKeep: 1 | ||
| NamespaceIndentation: None | ||
| ObjCBlockIndentWidth: 4 | ||
| ObjCSpaceAfterProperty: true | ||
| ObjCSpaceBeforeProtocolList: false | ||
| PenaltyBreakBeforeFirstCallParameter: 19 | ||
| PenaltyBreakComment: 300 | ||
| PenaltyBreakFirstLessLess: 120 | ||
| PenaltyBreakString: 1000 | ||
| PenaltyExcessCharacter: 1000000 | ||
| PenaltyReturnTypeOnItsOwnLine: 200 | ||
| PointerAlignment: Left | ||
| ReflowComments: true | ||
| SortIncludes: true | ||
| SpaceAfterCStyleCast: false | ||
| SpaceAfterTemplateKeyword: false | ||
| SpaceBeforeAssignmentOperators: true | ||
| SpaceBeforeParens: Never | ||
| SpaceInEmptyParentheses: false | ||
| SpacesBeforeTrailingComments: 1 | ||
| SpacesInAngles: false | ||
| SpacesInCStyleCastParentheses: false | ||
| SpacesInContainerLiterals: false | ||
| SpacesInParentheses: false | ||
| SpacesInSquareBrackets: false | ||
| Standard: Cpp11 | ||
| TabWidth: 8 | ||
| UseTab: Never | ||
| ... |
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 |
|---|---|---|
|
|
@@ -20,5 +20,6 @@ | |
| namespace nux { | ||
|
|
||
| DECLARE_MODULE(BOApproximation); | ||
| DECLARE_MODULE(XYZToMolecule); | ||
|
|
||
| } | ||
| } | ||
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,77 @@ | ||
| /* | ||
| * Copyright 2025 NWChemEx-Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "nux_modules.hpp" | ||
| #include <fstream> | ||
| #include <sstream> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace nux { | ||
|
|
||
| MODULE_CTOR(XYZToMolecule) { | ||
| satisfies_property_type<simde::MoleculeFromString>(); | ||
| add_submodule<simde::ZFromSymbol>("Z from symbol"); | ||
| add_submodule<simde::AtomFromZ>("Atom from z"); | ||
| } | ||
|
|
||
| MODULE_RUN(XYZToMolecule) { | ||
| const auto& [filename] = simde::MoleculeFromString::unwrap_inputs(inputs); | ||
|
|
||
| auto& z_from_sym = submods.at("Z from symbol"); | ||
| auto& atom_from_z = submods.at("Atom from z"); | ||
|
|
||
| chemist::Molecule mol; | ||
|
|
||
| std::ifstream xyz_file(filename); | ||
|
|
||
| if (!xyz_file) { | ||
| throw std::runtime_error("File not found: " + filename); | ||
| } | ||
|
|
||
| std::string line; | ||
|
|
||
| // Skips the 1st line of the file, associated with the number of | ||
| // atoms in the file, and the 2nd line, the comment line. | ||
| std::getline(xyz_file, line); | ||
| std::getline(xyz_file, line); | ||
|
|
||
| while (std::getline(xyz_file, line)) { | ||
| std::istringstream iss(line); | ||
| std::vector<std::string> tokens; | ||
| std::string token; | ||
| while (std::getline(iss, token, ' ')) { | ||
| if (token.size()) { tokens.emplace_back(token); } | ||
| } | ||
| auto Z = z_from_sym.run_as<simde::ZFromSymbol>(tokens.at(0)); | ||
| auto x = std::stod(tokens.at(1)); | ||
| auto y = std::stod(tokens.at(2)); | ||
| auto z = std::stod(tokens.at(3)); | ||
|
|
||
| auto atm = atom_from_z.run_as<simde::AtomFromZ>(Z); | ||
| atm.x() = x; | ||
| atm.y() = y; | ||
| atm.z() = z; | ||
| mol.push_back(atm); | ||
| } | ||
|
|
||
| xyz_file.close(); | ||
|
|
||
| auto rv = results(); | ||
| return simde::MoleculeFromString::wrap_results(rv, mol); | ||
| } | ||
|
|
||
| } // namespace nux | ||
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,71 @@ | ||
| /* | ||
| * Copyright 2024 NWChemEx-Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "../test_nux.hpp" | ||
| #include <nux/nux.hpp> | ||
|
|
||
| TEST_CASE("XYZToMolecule") { | ||
| pluginplay::ModuleManager mm; | ||
| nux::load_modules(mm); | ||
|
|
||
| auto make_atoms = [=](auto&& Z) { | ||
| REQUIRE(Z == 1); | ||
| double h_mass = 1837.4260218693814; | ||
| return simde::type::atom{"H", 1, h_mass, 0.0, 0.0, 0.0}; | ||
| }; | ||
|
|
||
| auto atom_mod = pluginplay::make_lambda<simde::AtomFromZ>(make_atoms); | ||
|
|
||
| auto z_mod = pluginplay::make_lambda<simde::ZFromSymbol>([=](auto&& symbol) { | ||
| return simde::type::atomic_number{1}; | ||
| }); | ||
|
|
||
| auto& xyz_mod = mm.at("XYZ To Molecule"); | ||
| xyz_mod.change_submod("Z from symbol", z_mod); | ||
| xyz_mod.change_submod("Atom from z", atom_mod); | ||
|
|
||
| SECTION("No XYZ file found") { | ||
| std::string file = "file.xyz"; | ||
| REQUIRE_THROWS_AS(xyz_mod.run_as<simde::MoleculeFromString>(file), std::runtime_error); | ||
| } | ||
jwaldrop107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| SECTION("Full XYZ To Molecule run") { | ||
| auto atom0{make_atoms(1)}; | ||
| auto atom1{make_atoms(1)}; | ||
| atom1.z() = 1; | ||
|
|
||
| simde::type::molecule test_mol{atom0, atom1}; | ||
|
|
||
| std::ofstream xyz_file; | ||
| xyz_file.open("h2.xyz"); | ||
|
|
||
| xyz_file << "2\n"; | ||
| xyz_file << "This is a comment!\n"; | ||
| xyz_file << "H 0 0 0\n"; | ||
| xyz_file << "H 0 0 1\n"; | ||
| xyz_file.close(); | ||
|
|
||
| std::string filename = "h2.xyz"; | ||
|
|
||
| auto mol = xyz_mod.run_as<simde::MoleculeFromString>(filename); | ||
|
|
||
| remove("h2.xyz"); | ||
| std::ifstream del_file("h2.xyz"); | ||
|
|
||
| REQUIRE(mol == test_mol); | ||
| REQUIRE(del_file.good() == false); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.