From 172b58db108abdb6b27cb43150b13395c7e3dcdf Mon Sep 17 00:00:00 2001 From: Jacob Heflin Date: Thu, 15 Aug 2024 13:12:25 -0500 Subject: [PATCH 1/7] Copy hydrocarbon files to hydrocarbon module in GhostFragment --- src/ghostfragment/ghostfragment.cpp | 2 + src/ghostfragment/hydrocarbon/hydrocarbon.cpp | 94 ++++++++++++++ src/ghostfragment/hydrocarbon/hydrocarbon.hpp | 76 ++++++++++++ src/ghostfragment/hydrocarbon/position.cpp | 115 ++++++++++++++++++ src/ghostfragment/hydrocarbon/position.hpp | 31 +++++ 5 files changed, 318 insertions(+) create mode 100644 src/ghostfragment/hydrocarbon/hydrocarbon.cpp create mode 100644 src/ghostfragment/hydrocarbon/hydrocarbon.hpp create mode 100644 src/ghostfragment/hydrocarbon/position.cpp create mode 100644 src/ghostfragment/hydrocarbon/position.hpp diff --git a/src/ghostfragment/ghostfragment.cpp b/src/ghostfragment/ghostfragment.cpp index 0d36bf16..1631b93c 100644 --- a/src/ghostfragment/ghostfragment.cpp +++ b/src/ghostfragment/ghostfragment.cpp @@ -20,6 +20,7 @@ #include "screening/screening.hpp" #include "topology/topology.hpp" #include +#include "hydrocarbon/hydrocaron.hpp" namespace ghostfragment { @@ -29,6 +30,7 @@ void load_modules(pluginplay::ModuleManager& mm) { drivers::load_modules(mm); fragmenting::load_modules(mm); // screening::load_modules(mm); + hydrocarbon::load_modules(mm); capping::set_defaults(mm); topology::set_defaults(mm); diff --git a/src/ghostfragment/hydrocarbon/hydrocarbon.cpp b/src/ghostfragment/hydrocarbon/hydrocarbon.cpp new file mode 100644 index 00000000..681d0334 --- /dev/null +++ b/src/ghostfragment/hydrocarbon/hydrocarbon.cpp @@ -0,0 +1,94 @@ +/* + * Copyright 2024 GhostFragment + * + * 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 "hydrocarbon.hpp" +#include "position.hpp" + +#define C_C_BOND 2.89 +#define H_C_BOND 2.06 +#define ANGLE 109.5 + +#define C_MASS 21874.662 +#define H_MASS 1837.289 +#define C_NPROTON 6 +#define H_NPROTON 1 + +namespace testing { + +chemist::Molecule hydrocarbon(int num_carbon) { + chemist::Molecule m; + + // A log of all carbon atom positions. + // Used to determine the position of the next carbon and connected hydrogens + std::vector source_coords{0.0, 0.0, 0.0}; + source_coords.reserve(num_carbon * 3); + + // The first carbon atom positioned at {0, 0, 0} + m.push_back(chemist::Atom("C", C_NPROTON, C_MASS, 0, 0, 0)); + + // Positions each of the following carbon atoms + for(int i = 1; i < num_carbon; i++) { + // Finds the new coordinates using the previous ones + std::array coords = + position_carbon(source_coords, C_C_BOND, i - 1, ANGLE); + + // Adds the new atom + m.push_back(chemist::Atom("C", C_NPROTON, C_MASS, coords[0], coords[1], + coords[2])); + + // Logs the new atoms coordinates + for(int j = 0; j < 3; j++) { source_coords[(3 * i) + j] = coords[j]; } + } + + // Positions each connected hydrogen atom + for(int i = 0; i < num_carbon; i++) { + // Creates the first hydrogen in the chain + if(i == 0) { + // Finds the coordinates using the carbon + std::array coords = + position_hydrogen(source_coords, 2, i, H_C_BOND, ANGLE); + + // Adds the new atom + m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], + coords[1], coords[2])); + } + + // Creates the side hydrogens + for(int j = 0; j <= 1; j++) { + // Finds the coordinates using the carbon + std::array coords = + position_hydrogen(source_coords, j, i, H_C_BOND, ANGLE); + + // Adds the new atom + m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], + coords[1], coords[2])); + } + + if(i == num_carbon - 1) { + // Finds the coordinates using the carbon + std::array coords = + position_hydrogen(source_coords, 3, i, H_C_BOND, ANGLE); + + // Adds the new atom + m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], + coords[1], coords[2])); + } + } + + return m; +} + +} // namespace testing diff --git a/src/ghostfragment/hydrocarbon/hydrocarbon.hpp b/src/ghostfragment/hydrocarbon/hydrocarbon.hpp new file mode 100644 index 00000000..3408c743 --- /dev/null +++ b/src/ghostfragment/hydrocarbon/hydrocarbon.hpp @@ -0,0 +1,76 @@ +/* + * Copyright 2024 GhostFragment + * + * 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. + */ + +#pragma once +#include +#include +#include +#include +#include +#include + +namespace testing { + +chemist::Molecule hydrocarbon(int num_carbon); + +inline auto hydrocarbon_connectivity(std::size_t N) { + // Probably a better way, but this works + const auto n_atoms = hydrocarbon(N).size(); + + chemist::topology::ConnectivityTable conns(n_atoms); + if(N == 0) return conns; + + // First N-1 atoms are carbons + // carbon 0 is bonded to atom N + // carbon i is bonded to carbon i + 1 (assuming i + 1 != N) + // carbon i is bonded to hydrogens N + 2*i + 1 and N + 2*i + 2 + // carbon N - 1 is bonded to atom n_atoms - 1 + std::size_t h_counter = N; + conns.add_bond(0, h_counter); + for(std::size_t i = 0; i < N; ++i) { + if(i + 1 < N) conns.add_bond(i, i + 1); + conns.add_bond(i, ++h_counter); + conns.add_bond(i, ++h_counter); + } + conns.add_bond(N - 1, ++h_counter); + return conns; +} + +/// Fragments a hydrocarbon system (fragments are M carbons +/// with M-1 carbon overlap with adjacent fragments, +/// hydrocarbon is N carbons long) +inline auto hydrocarbon_fragmented_nuclei(std::size_t N, std::size_t M) { + auto hydrocarbon_n = hydrocarbon(N); + using return_type = chemist::fragmenting::FragmentedNuclei; + return_type frags(hydrocarbon_n.nuclei()); + + // Define fragment to add to fragmented nuclei + std::vector frag{}; + for(std::size_t i = 0; i < N - (M - 1); ++i) { + frag = {}; + for(std::size_t j = i; j < i + M; ++j) { + frag.push_back(j); + if(j == 0) { frag.push_back(N); } + frag.push_back(2 * j + 1 + N); + frag.push_back(2 * j + 2 + N); + if(j == N - 1) { frag.push_back(2 * j + 3 + N); } + } + frags.insert(frag.begin(), frag.end()); + } + return frags; +} + +} // namespace testing diff --git a/src/ghostfragment/hydrocarbon/position.cpp b/src/ghostfragment/hydrocarbon/position.cpp new file mode 100644 index 00000000..7280696b --- /dev/null +++ b/src/ghostfragment/hydrocarbon/position.cpp @@ -0,0 +1,115 @@ +/* + * Copyright 2024 GhostFragment + * + * 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 "position.hpp" + +namespace testing { + +std::array position_carbon(const std::vector& source_coords, + float carbon_bond, int num, + float angle_deg) { + // Creates the pointer for positions + std::array coords{0.0, 0.0, 0.0}; + // Convert degrees to radians + float angle_rad = angle_deg * (3.14159265358979 / 180); + + // Sets the distance in each axis from the source coordinates + // X: r*sin(theta) + // Y: r*cos(theta) + // Z: 0 + coords[0] = carbon_bond * sin(angle_rad / 2); + coords[1] = carbon_bond * cos(angle_rad / 2); + coords[2] = 0; + + // If the source atom is even, the new one must go up, otherwise, + // it must go down + coords[1] *= (num % 2 == 0) ? 1 : -1; + + for(int i = 0; i < 3; i++) { coords[i] += source_coords[(3 * num) + i]; } + + return coords; +} + +std::array position_hydrogen(const std::vector& source_coords, + int flag, int num, float hydrogen_bond, + float angle_deg) { + // Creates the pointer for positions + std::array coords{0.0, 0.0, 0.0}; + // Convert degrees to radians + float angle_rad = angle_deg * (3.14159 / 180); + + // Because multiple hydrogen atoms get the same carbon atom, they need to be + // defined by which place they are taking + switch(flag) { + // Goes behind the carbon (z is negative) + case 0: + // X: 0 + // Y: r*cos(theta) + // Z: r*sin(theta) + coords[0] = 0; + coords[1] = hydrogen_bond * cos(angle_rad / 2); + coords[2] = (-1) * hydrogen_bond * sin(angle_rad / 2); + + // If the carbon atom is odd, the hydrogen must be above, otherwise, + // it must be below + coords[1] *= (num % 2 == 0) ? -1 : 1; + break; + + // Goes in front of the carbon (z is positive) + case 1: + // X: 0 + // Y: r*cos(theta) + // Z: r*sin(theta) + coords[0] = 0; + coords[1] = hydrogen_bond * cos(angle_rad / 2); + coords[2] = hydrogen_bond * sin(angle_rad / 2); + + // If the carbon atom is odd, the hydrogen must be above, otherwise, + // it must be below + coords[1] *= (num % 2 == 0) ? -1 : 1; + break; + + // Goes to the left of the first carbon + case 2: + // X: r*sin(theta) + // Y: r*cos(theta) + // Z: 0 + coords[0] = (-1) * hydrogen_bond * sin(angle_rad / 2); + coords[1] = hydrogen_bond * cos(angle_rad / 2); + coords[2] = 0; + break; + + // Goes to the right of the last carbon + case 3: + // X: r*sin(theta) + // Y: r*cos(theta) + // Z: 0 + coords[0] = hydrogen_bond * sin(angle_rad / 2); + coords[1] = hydrogen_bond * cos(angle_rad / 2); + coords[2] = 0; + + // If the last carbon is even, the hydrogen must be above, + // otherwise, it must be below + coords[1] *= (num % 2 == 0) ? 1 : -1; + break; + } + + for(int i = 0; i < 3; i++) { coords[i] += source_coords[(3 * num) + i]; } + + return coords; +} + +} // namespace testing diff --git a/src/ghostfragment/hydrocarbon/position.hpp b/src/ghostfragment/hydrocarbon/position.hpp new file mode 100644 index 00000000..5f832a91 --- /dev/null +++ b/src/ghostfragment/hydrocarbon/position.hpp @@ -0,0 +1,31 @@ +/* + * Copyright 2024 GhostFragment + * + * 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. + */ + +#pragma once +#include +#include +#include + +namespace testing { + +std::array position_carbon(const std::vector& source_coords, + float carbon_bond, int num, + float angle_deg); + +std::array position_hydrogen(const std::vector& source_coords, + int flag, int num, float hydrogen_bond, + float angle_deg); +} // namespace testing From 70bee89f530bf28b0958c50234836da37c5707a8 Mon Sep 17 00:00:00 2001 From: Jacob Heflin Date: Thu, 15 Aug 2024 14:15:27 -0500 Subject: [PATCH 2/7] Start of constructing hydrocarbon module --- src/ghostfragment/hydrocarbon/hydrocarbon.cpp | 136 ++++++++---------- src/ghostfragment/hydrocarbon/make_hc.hpp | 16 +++ 2 files changed, 79 insertions(+), 73 deletions(-) create mode 100644 src/ghostfragment/hydrocarbon/make_hc.hpp diff --git a/src/ghostfragment/hydrocarbon/hydrocarbon.cpp b/src/ghostfragment/hydrocarbon/hydrocarbon.cpp index 681d0334..288dee4b 100644 --- a/src/ghostfragment/hydrocarbon/hydrocarbon.cpp +++ b/src/ghostfragment/hydrocarbon/hydrocarbon.cpp @@ -1,94 +1,84 @@ -/* - * Copyright 2024 GhostFragment - * - * 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 "hydrocarbon.hpp" -#include "position.hpp" +#include -#define C_C_BOND 2.89 -#define H_C_BOND 2.06 -#define ANGLE 109.5 +namespace ghostfragment::hydrocarbon { -#define C_MASS 21874.662 -#define H_MASS 1837.289 -#define C_NPROTON 6 -#define H_NPROTON 1 +using n_type = unsigned short; -namespace testing { +const auto mod_desc = R"( +Hydrocarbon Chain Generator +___________________________ -chemist::Molecule hydrocarbon(int num_carbon) { - chemist::Molecule m; +This module generates carbon chains of given "n" - // A log of all carbon atom positions. - // Used to determine the position of the next carbon and connected hydrogens - std::vector source_coords{0.0, 0.0, 0.0}; - source_coords.reserve(num_carbon * 3); +)"; - // The first carbon atom positioned at {0, 0, 0} - m.push_back(chemist::Atom("C", C_NPROTON, C_MASS, 0, 0, 0)); +MODULE_CTOR(hydrocarbon) { + description(mod_desc); + satisfies_property_type - // Positions each of the following carbon atoms - for(int i = 1; i < num_carbon; i++) { - // Finds the new coordinates using the previous ones - std::array coords = - position_carbon(source_coords, C_C_BOND, i - 1, ANGLE); + // Inputs/modules controlling + add_input("n").set_default(n_type(1)); +} - // Adds the new atom - m.push_back(chemist::Atom("C", C_NPROTON, C_MASS, coords[0], coords[1], - coords[2])); +MODULE_RUN(hydrocarbon) { + auto num_carbon = inputs.at("n").value(); + chemist::Molecule hydrocarbon(int num_carbon); + chemist::Molecule m; - // Logs the new atoms coordinates - for(int j = 0; j < 3; j++) { source_coords[(3 * i) + j] = coords[j]; } - } + // A log of all carbon atom positions. + // Used to determine the position of the next carbon and connected hydrogens + std::vector source_coords{0.0, 0.0, 0.0}; + source_coords.reserve(num_carbon * 3); + + // The first carbon atom positioned at {0, 0, 0} + m.push_back(chemist::Atom("C", C_NPROTON, C_MASS, 0, 0, 0)); + + // Positions each of the following carbon atoms + for(int i = 1; i < num_carbon; i++) { + // Finds the new coordinates using the previous ones + std::array coords = position_carbon(source_coords, C_C_BOND, i - 1, ANGLE); + + // Adds the new atom + m.push_back(chemist::Atom("C", C_NPROTON, C_MASS, coords[0], coords[1], coords[2])); - // Positions each connected hydrogen atom - for(int i = 0; i < num_carbon; i++) { - // Creates the first hydrogen in the chain - if(i == 0) { - // Finds the coordinates using the carbon - std::array coords = - position_hydrogen(source_coords, 2, i, H_C_BOND, ANGLE); - - // Adds the new atom - m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], - coords[1], coords[2])); + // Logs the new atoms coordinates + for(int j = 0; j < 3; j++) { source_coords[(3 * i) + j] = coords[j]; } + } + + // Positions each connected hydrogen atom + for(int i = 0; i < num_carbon; i++) { + // Creates the first hydrogen in the chain + if(i == 0) { + // Finds the coordinates using the carbon + std::array coords = position_hydrogen(source_coords, 2, i, H_C_BOND, ANGLE); + + // Adds the new atom + m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], coords[1], coords[2])); } - // Creates the side hydrogens - for(int j = 0; j <= 1; j++) { - // Finds the coordinates using the carbon - std::array coords = - position_hydrogen(source_coords, j, i, H_C_BOND, ANGLE); + // Creates the side hydrogens + for(int j = 0; j <= 1; j++) { + // Finds the coordinates using the carbon + std::array coords = position_hydrogen(source_coords, j, i, H_C_BOND, ANGLE); - // Adds the new atom - m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], - coords[1], coords[2])); + // Adds the new atom + m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], coords[1], coords[2])); } - if(i == num_carbon - 1) { - // Finds the coordinates using the carbon - std::array coords = - position_hydrogen(source_coords, 3, i, H_C_BOND, ANGLE); + if(i == num_carbon - 1) { + // Finds the coordinates using the carbon + std::array coords = position_hydrogen(source_coords, 3, i, H_C_BOND, ANGLE); - // Adds the new atom - m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], - coords[1], coords[2])); + // Adds the new atom + m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], coords[1], coords[2])); } } + auto rv = results(); + return simde::MoleculeToString::wrap_results(rv, m); + + } + - return m; -} -} // namespace testing +}// namespace ghostfragment::hydrocarbon diff --git a/src/ghostfragment/hydrocarbon/make_hc.hpp b/src/ghostfragment/hydrocarbon/make_hc.hpp new file mode 100644 index 00000000..84279512 --- /dev/null +++ b/src/ghostfragment/hydrocarbon/make_hc.hpp @@ -0,0 +1,16 @@ +#pragma once +#include + +namespace ghostfragment::hydrocarbon { + +DECLARE_MODULE(make_hc); + +inline void load_modules(pluginplay::ModuleManager& mm) { + mm.add_module("Make Hydrocarbon"); +} + +inline void set_defaults(pluginplay::ModuleManager& mm) { + +} + +} // namespace ghostfragment::hydrocarbon From ab2217f06befb3a01292d7cf0acf1ca4c4266ea2 Mon Sep 17 00:00:00 2001 From: Jacob Heflin Date: Thu, 15 Aug 2024 14:15:44 -0500 Subject: [PATCH 3/7] Start of constructing hydrocarbon module --- src/ghostfragment/ghostfragment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ghostfragment/ghostfragment.cpp b/src/ghostfragment/ghostfragment.cpp index 1631b93c..d1a731b5 100644 --- a/src/ghostfragment/ghostfragment.cpp +++ b/src/ghostfragment/ghostfragment.cpp @@ -20,7 +20,7 @@ #include "screening/screening.hpp" #include "topology/topology.hpp" #include -#include "hydrocarbon/hydrocaron.hpp" +#include "hydrocarbon/make_hc.hpp" namespace ghostfragment { From 432845c3ce18527b9405a987edd14080e2664ea4 Mon Sep 17 00:00:00 2001 From: Jacob Heflin Date: Fri, 16 Aug 2024 08:00:09 -0500 Subject: [PATCH 4/7] Chamged code to better reflect current formatting --- .kdev4/GhostFragment.kdev4 | 33 +++++ GhostFragment.kdev4 | 4 + src/ghostfragment/ghostfragment.cpp | 2 +- .../hydrocarbon/{make_hc.hpp => hc.hpp} | 4 +- src/ghostfragment/hydrocarbon/hydrocarbon.cpp | 136 ++++++++++-------- src/ghostfragment/hydrocarbon/hydrocarbon.hpp | 2 +- .../hydrocarbon/makehydrocarbon.cpp | 31 ++++ 7 files changed, 145 insertions(+), 67 deletions(-) create mode 100644 .kdev4/GhostFragment.kdev4 create mode 100644 GhostFragment.kdev4 rename src/ghostfragment/hydrocarbon/{make_hc.hpp => hc.hpp} (72%) create mode 100644 src/ghostfragment/hydrocarbon/makehydrocarbon.cpp diff --git a/.kdev4/GhostFragment.kdev4 b/.kdev4/GhostFragment.kdev4 new file mode 100644 index 00000000..583d53ce --- /dev/null +++ b/.kdev4/GhostFragment.kdev4 @@ -0,0 +1,33 @@ +[Buildset] +BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x1a\x00G\x00h\x00o\x00s\x00t\x00F\x00r\x00a\x00g\x00m\x00e\x00n\x00t) + +[CMake] +Build Directory Count=1 +Current Build Directory Index-Host System=0 + +[CMake][CMake Build Directory 0] +Build Directory Path=/home/jacob/Projects/GhostFragment/build +Build Type=Release +CMake Binary=/usr/bin/cmake +CMake Executable=/usr/bin/cmake +Environment Profile= +Extra Arguments=-DNWX_MODULE_DIRECTORY=/home/jacob/Projects/GhostFragment/install +Install Directory=/home/jacob/Projects/GhostFragment/install +Runtime=Host System + +[CustomDefinesAndIncludes][ProjectPath0] +Path=. +parseAmbiguousAsCPP=true +parserArguments=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++17 +parserArgumentsC=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c99 +parserArgumentsCuda=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11 +parserArgumentsOpenCL=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -cl-std=CL1.1 + +[CustomDefinesAndIncludes][ProjectPath0][Compiler] +Name=Clang + +[Project] +VersionControlSupport=kdevgit + +[pythonsupport] +interpreter=/home/jacob/Environments/base/bin/python diff --git a/GhostFragment.kdev4 b/GhostFragment.kdev4 new file mode 100644 index 00000000..b0eee033 --- /dev/null +++ b/GhostFragment.kdev4 @@ -0,0 +1,4 @@ +[Project] +CreatedFrom=CMakeLists.txt +Manager=KDevCMakeManager +Name=GhostFragment diff --git a/src/ghostfragment/ghostfragment.cpp b/src/ghostfragment/ghostfragment.cpp index d1a731b5..2225d012 100644 --- a/src/ghostfragment/ghostfragment.cpp +++ b/src/ghostfragment/ghostfragment.cpp @@ -20,7 +20,7 @@ #include "screening/screening.hpp" #include "topology/topology.hpp" #include -#include "hydrocarbon/make_hc.hpp" +#include "hydrocarbon/hc.hpp" namespace ghostfragment { diff --git a/src/ghostfragment/hydrocarbon/make_hc.hpp b/src/ghostfragment/hydrocarbon/hc.hpp similarity index 72% rename from src/ghostfragment/hydrocarbon/make_hc.hpp rename to src/ghostfragment/hydrocarbon/hc.hpp index 84279512..f2d76c20 100644 --- a/src/ghostfragment/hydrocarbon/make_hc.hpp +++ b/src/ghostfragment/hydrocarbon/hc.hpp @@ -3,10 +3,10 @@ namespace ghostfragment::hydrocarbon { -DECLARE_MODULE(make_hc); +DECLARE_MODULE(makehydrocarbon); inline void load_modules(pluginplay::ModuleManager& mm) { - mm.add_module("Make Hydrocarbon"); + mm.add_module("Generate Hydrocabon"); } inline void set_defaults(pluginplay::ModuleManager& mm) { diff --git a/src/ghostfragment/hydrocarbon/hydrocarbon.cpp b/src/ghostfragment/hydrocarbon/hydrocarbon.cpp index 288dee4b..681d0334 100644 --- a/src/ghostfragment/hydrocarbon/hydrocarbon.cpp +++ b/src/ghostfragment/hydrocarbon/hydrocarbon.cpp @@ -1,84 +1,94 @@ -#include "hydrocarbon.hpp" -#include - -namespace ghostfragment::hydrocarbon { - -using n_type = unsigned short; +/* + * Copyright 2024 GhostFragment + * + * 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. + */ -const auto mod_desc = R"( -Hydrocarbon Chain Generator -___________________________ - -This module generates carbon chains of given "n" +#include "hydrocarbon.hpp" +#include "position.hpp" -)"; +#define C_C_BOND 2.89 +#define H_C_BOND 2.06 +#define ANGLE 109.5 -MODULE_CTOR(hydrocarbon) { - description(mod_desc); - satisfies_property_type +#define C_MASS 21874.662 +#define H_MASS 1837.289 +#define C_NPROTON 6 +#define H_NPROTON 1 - // Inputs/modules controlling - add_input("n").set_default(n_type(1)); -} +namespace testing { -MODULE_RUN(hydrocarbon) { - auto num_carbon = inputs.at("n").value(); - chemist::Molecule hydrocarbon(int num_carbon); - chemist::Molecule m; +chemist::Molecule hydrocarbon(int num_carbon) { + chemist::Molecule m; - // A log of all carbon atom positions. - // Used to determine the position of the next carbon and connected hydrogens - std::vector source_coords{0.0, 0.0, 0.0}; - source_coords.reserve(num_carbon * 3); + // A log of all carbon atom positions. + // Used to determine the position of the next carbon and connected hydrogens + std::vector source_coords{0.0, 0.0, 0.0}; + source_coords.reserve(num_carbon * 3); - // The first carbon atom positioned at {0, 0, 0} - m.push_back(chemist::Atom("C", C_NPROTON, C_MASS, 0, 0, 0)); + // The first carbon atom positioned at {0, 0, 0} + m.push_back(chemist::Atom("C", C_NPROTON, C_MASS, 0, 0, 0)); - // Positions each of the following carbon atoms - for(int i = 1; i < num_carbon; i++) { - // Finds the new coordinates using the previous ones - std::array coords = position_carbon(source_coords, C_C_BOND, i - 1, ANGLE); + // Positions each of the following carbon atoms + for(int i = 1; i < num_carbon; i++) { + // Finds the new coordinates using the previous ones + std::array coords = + position_carbon(source_coords, C_C_BOND, i - 1, ANGLE); - // Adds the new atom - m.push_back(chemist::Atom("C", C_NPROTON, C_MASS, coords[0], coords[1], coords[2])); + // Adds the new atom + m.push_back(chemist::Atom("C", C_NPROTON, C_MASS, coords[0], coords[1], + coords[2])); - // Logs the new atoms coordinates - for(int j = 0; j < 3; j++) { source_coords[(3 * i) + j] = coords[j]; } - } - - // Positions each connected hydrogen atom - for(int i = 0; i < num_carbon; i++) { - // Creates the first hydrogen in the chain - if(i == 0) { - // Finds the coordinates using the carbon - std::array coords = position_hydrogen(source_coords, 2, i, H_C_BOND, ANGLE); + // Logs the new atoms coordinates + for(int j = 0; j < 3; j++) { source_coords[(3 * i) + j] = coords[j]; } + } - // Adds the new atom - m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], coords[1], coords[2])); + // Positions each connected hydrogen atom + for(int i = 0; i < num_carbon; i++) { + // Creates the first hydrogen in the chain + if(i == 0) { + // Finds the coordinates using the carbon + std::array coords = + position_hydrogen(source_coords, 2, i, H_C_BOND, ANGLE); + + // Adds the new atom + m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], + coords[1], coords[2])); } - // Creates the side hydrogens - for(int j = 0; j <= 1; j++) { - // Finds the coordinates using the carbon - std::array coords = position_hydrogen(source_coords, j, i, H_C_BOND, ANGLE); + // Creates the side hydrogens + for(int j = 0; j <= 1; j++) { + // Finds the coordinates using the carbon + std::array coords = + position_hydrogen(source_coords, j, i, H_C_BOND, ANGLE); - // Adds the new atom - m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], coords[1], coords[2])); + // Adds the new atom + m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], + coords[1], coords[2])); } - if(i == num_carbon - 1) { - // Finds the coordinates using the carbon - std::array coords = position_hydrogen(source_coords, 3, i, H_C_BOND, ANGLE); + if(i == num_carbon - 1) { + // Finds the coordinates using the carbon + std::array coords = + position_hydrogen(source_coords, 3, i, H_C_BOND, ANGLE); - // Adds the new atom - m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], coords[1], coords[2])); + // Adds the new atom + m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], + coords[1], coords[2])); } } - auto rv = results(); - return simde::MoleculeToString::wrap_results(rv, m); - - } - + return m; +} -}// namespace ghostfragment::hydrocarbon +} // namespace testing diff --git a/src/ghostfragment/hydrocarbon/hydrocarbon.hpp b/src/ghostfragment/hydrocarbon/hydrocarbon.hpp index 3408c743..fad31a60 100644 --- a/src/ghostfragment/hydrocarbon/hydrocarbon.hpp +++ b/src/ghostfragment/hydrocarbon/hydrocarbon.hpp @@ -1,4 +1,4 @@ -/* +()/* * Copyright 2024 GhostFragment * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/src/ghostfragment/hydrocarbon/makehydrocarbon.cpp b/src/ghostfragment/hydrocarbon/makehydrocarbon.cpp new file mode 100644 index 00000000..cd461159 --- /dev/null +++ b/src/ghostfragment/hydrocarbon/makehydrocarbon.cpp @@ -0,0 +1,31 @@ +#include +#include "hydrocarbon.hpp" +#include "hc.hpp" +#include + +namespace ghostfragment::hydrocarbon { + +using n_type = unsigned short; + +const auto mod_desc = R"( +Hydrocarbon Chain Generator +--------------------------- +)"; + +MODULE_CTOR(makehydrocarbon) { + description(mod_desc); + satisfies_property_type(); + + add_input("n") + .set_description("Number of carbons in carbon chain to generate") + .set_default(n_type(1)); +} + +MODULE_RUN(makehydrocarbon) { + auto num_carbon = inputs.at("n").value(); + + chemist::Molecule hc = hydrocarbon(int num_carbon); + + return hc; +} +} From 66bf335a74d2435fb737c9f559eae0ba59d25cbd Mon Sep 17 00:00:00 2001 From: Jacob Heflin Date: Fri, 16 Aug 2024 08:04:12 -0500 Subject: [PATCH 5/7] Added to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 44d99644..007dc02e 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ __pycache__ # These are directories used by IDEs for storing settings .idea/ .vscode/ +.cache/ # These are common Python virtual enviornment directory names venv/ From dc5e3090f4644a5d96abb36f4388e871efe21ba4 Mon Sep 17 00:00:00 2001 From: "Ryan M. Richard" Date: Fri, 16 Aug 2024 09:55:15 -0500 Subject: [PATCH 6/7] cleanup --- .gitignore | 2 + .kdev4/GhostFragment.kdev4 | 33 ----- GhostFragment.kdev4 | 4 - src/ghostfragment/hydrocarbon/hc.hpp | 16 --- src/ghostfragment/hydrocarbon/hydrocarbon.cpp | 94 -------------- src/ghostfragment/hydrocarbon/hydrocarbon.hpp | 72 ++--------- .../hydrocarbon/make_hydrocarbon.cpp | 29 ++++- .../hydrocarbon/makehydrocarbon.cpp | 31 ----- src/ghostfragment/hydrocarbon/position.cpp | 5 +- src/ghostfragment/hydrocarbon/position.hpp | 5 +- .../testing/hydrocarbon/hydrocarbon.hpp | 3 +- .../testing/hydrocarbon/position.cpp | 115 ------------------ .../testing/hydrocarbon/position.hpp | 31 ----- 13 files changed, 40 insertions(+), 400 deletions(-) delete mode 100644 .kdev4/GhostFragment.kdev4 delete mode 100644 GhostFragment.kdev4 delete mode 100644 src/ghostfragment/hydrocarbon/hc.hpp delete mode 100644 src/ghostfragment/hydrocarbon/hydrocarbon.cpp rename tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/hydrocarbon.cpp => src/ghostfragment/hydrocarbon/make_hydrocarbon.cpp (85%) delete mode 100644 src/ghostfragment/hydrocarbon/makehydrocarbon.cpp delete mode 100644 tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/position.cpp delete mode 100644 tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/position.hpp diff --git a/.gitignore b/.gitignore index 007dc02e..ebb21f06 100644 --- a/.gitignore +++ b/.gitignore @@ -56,4 +56,6 @@ toolchain.cmake install/ .DS_Store +.kdev4/ +GhostFragment.kdev4 diff --git a/.kdev4/GhostFragment.kdev4 b/.kdev4/GhostFragment.kdev4 deleted file mode 100644 index 583d53ce..00000000 --- a/.kdev4/GhostFragment.kdev4 +++ /dev/null @@ -1,33 +0,0 @@ -[Buildset] -BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x1a\x00G\x00h\x00o\x00s\x00t\x00F\x00r\x00a\x00g\x00m\x00e\x00n\x00t) - -[CMake] -Build Directory Count=1 -Current Build Directory Index-Host System=0 - -[CMake][CMake Build Directory 0] -Build Directory Path=/home/jacob/Projects/GhostFragment/build -Build Type=Release -CMake Binary=/usr/bin/cmake -CMake Executable=/usr/bin/cmake -Environment Profile= -Extra Arguments=-DNWX_MODULE_DIRECTORY=/home/jacob/Projects/GhostFragment/install -Install Directory=/home/jacob/Projects/GhostFragment/install -Runtime=Host System - -[CustomDefinesAndIncludes][ProjectPath0] -Path=. -parseAmbiguousAsCPP=true -parserArguments=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++17 -parserArgumentsC=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c99 -parserArgumentsCuda=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11 -parserArgumentsOpenCL=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -cl-std=CL1.1 - -[CustomDefinesAndIncludes][ProjectPath0][Compiler] -Name=Clang - -[Project] -VersionControlSupport=kdevgit - -[pythonsupport] -interpreter=/home/jacob/Environments/base/bin/python diff --git a/GhostFragment.kdev4 b/GhostFragment.kdev4 deleted file mode 100644 index b0eee033..00000000 --- a/GhostFragment.kdev4 +++ /dev/null @@ -1,4 +0,0 @@ -[Project] -CreatedFrom=CMakeLists.txt -Manager=KDevCMakeManager -Name=GhostFragment diff --git a/src/ghostfragment/hydrocarbon/hc.hpp b/src/ghostfragment/hydrocarbon/hc.hpp deleted file mode 100644 index f2d76c20..00000000 --- a/src/ghostfragment/hydrocarbon/hc.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once -#include - -namespace ghostfragment::hydrocarbon { - -DECLARE_MODULE(makehydrocarbon); - -inline void load_modules(pluginplay::ModuleManager& mm) { - mm.add_module("Generate Hydrocabon"); -} - -inline void set_defaults(pluginplay::ModuleManager& mm) { - -} - -} // namespace ghostfragment::hydrocarbon diff --git a/src/ghostfragment/hydrocarbon/hydrocarbon.cpp b/src/ghostfragment/hydrocarbon/hydrocarbon.cpp deleted file mode 100644 index 681d0334..00000000 --- a/src/ghostfragment/hydrocarbon/hydrocarbon.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2024 GhostFragment - * - * 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 "hydrocarbon.hpp" -#include "position.hpp" - -#define C_C_BOND 2.89 -#define H_C_BOND 2.06 -#define ANGLE 109.5 - -#define C_MASS 21874.662 -#define H_MASS 1837.289 -#define C_NPROTON 6 -#define H_NPROTON 1 - -namespace testing { - -chemist::Molecule hydrocarbon(int num_carbon) { - chemist::Molecule m; - - // A log of all carbon atom positions. - // Used to determine the position of the next carbon and connected hydrogens - std::vector source_coords{0.0, 0.0, 0.0}; - source_coords.reserve(num_carbon * 3); - - // The first carbon atom positioned at {0, 0, 0} - m.push_back(chemist::Atom("C", C_NPROTON, C_MASS, 0, 0, 0)); - - // Positions each of the following carbon atoms - for(int i = 1; i < num_carbon; i++) { - // Finds the new coordinates using the previous ones - std::array coords = - position_carbon(source_coords, C_C_BOND, i - 1, ANGLE); - - // Adds the new atom - m.push_back(chemist::Atom("C", C_NPROTON, C_MASS, coords[0], coords[1], - coords[2])); - - // Logs the new atoms coordinates - for(int j = 0; j < 3; j++) { source_coords[(3 * i) + j] = coords[j]; } - } - - // Positions each connected hydrogen atom - for(int i = 0; i < num_carbon; i++) { - // Creates the first hydrogen in the chain - if(i == 0) { - // Finds the coordinates using the carbon - std::array coords = - position_hydrogen(source_coords, 2, i, H_C_BOND, ANGLE); - - // Adds the new atom - m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], - coords[1], coords[2])); - } - - // Creates the side hydrogens - for(int j = 0; j <= 1; j++) { - // Finds the coordinates using the carbon - std::array coords = - position_hydrogen(source_coords, j, i, H_C_BOND, ANGLE); - - // Adds the new atom - m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], - coords[1], coords[2])); - } - - if(i == num_carbon - 1) { - // Finds the coordinates using the carbon - std::array coords = - position_hydrogen(source_coords, 3, i, H_C_BOND, ANGLE); - - // Adds the new atom - m.push_back(chemist::Atom("H", H_NPROTON, H_MASS, coords[0], - coords[1], coords[2])); - } - } - - return m; -} - -} // namespace testing diff --git a/src/ghostfragment/hydrocarbon/hydrocarbon.hpp b/src/ghostfragment/hydrocarbon/hydrocarbon.hpp index fad31a60..819bada8 100644 --- a/src/ghostfragment/hydrocarbon/hydrocarbon.hpp +++ b/src/ghostfragment/hydrocarbon/hydrocarbon.hpp @@ -1,76 +1,18 @@ -()/* - * Copyright 2024 GhostFragment - * - * 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. - */ - #pragma once -#include -#include -#include -#include -#include -#include +#include -namespace testing { +namespace ghostfragment::hydrocarbon { chemist::Molecule hydrocarbon(int num_carbon); -inline auto hydrocarbon_connectivity(std::size_t N) { - // Probably a better way, but this works - const auto n_atoms = hydrocarbon(N).size(); - - chemist::topology::ConnectivityTable conns(n_atoms); - if(N == 0) return conns; +DECLARE_MODULE(MakeHydrocarbon); - // First N-1 atoms are carbons - // carbon 0 is bonded to atom N - // carbon i is bonded to carbon i + 1 (assuming i + 1 != N) - // carbon i is bonded to hydrogens N + 2*i + 1 and N + 2*i + 2 - // carbon N - 1 is bonded to atom n_atoms - 1 - std::size_t h_counter = N; - conns.add_bond(0, h_counter); - for(std::size_t i = 0; i < N; ++i) { - if(i + 1 < N) conns.add_bond(i, i + 1); - conns.add_bond(i, ++h_counter); - conns.add_bond(i, ++h_counter); - } - conns.add_bond(N - 1, ++h_counter); - return conns; +inline void load_modules(pluginplay::ModuleManager& mm) { + mm.add_module("Generate a straight chain alkane"); } -/// Fragments a hydrocarbon system (fragments are M carbons -/// with M-1 carbon overlap with adjacent fragments, -/// hydrocarbon is N carbons long) -inline auto hydrocarbon_fragmented_nuclei(std::size_t N, std::size_t M) { - auto hydrocarbon_n = hydrocarbon(N); - using return_type = chemist::fragmenting::FragmentedNuclei; - return_type frags(hydrocarbon_n.nuclei()); +inline void set_defaults(pluginplay::ModuleManager& mm) { - // Define fragment to add to fragmented nuclei - std::vector frag{}; - for(std::size_t i = 0; i < N - (M - 1); ++i) { - frag = {}; - for(std::size_t j = i; j < i + M; ++j) { - frag.push_back(j); - if(j == 0) { frag.push_back(N); } - frag.push_back(2 * j + 1 + N); - frag.push_back(2 * j + 2 + N); - if(j == N - 1) { frag.push_back(2 * j + 3 + N); } - } - frags.insert(frag.begin(), frag.end()); - } - return frags; } -} // namespace testing +} // namespace ghostfragment::hydrocarbon diff --git a/tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/hydrocarbon.cpp b/src/ghostfragment/hydrocarbon/make_hydrocarbon.cpp similarity index 85% rename from tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/hydrocarbon.cpp rename to src/ghostfragment/hydrocarbon/make_hydrocarbon.cpp index 681d0334..c502ab5a 100644 --- a/tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/hydrocarbon.cpp +++ b/src/ghostfragment/hydrocarbon/make_hydrocarbon.cpp @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "hydrocarbon.hpp" #include "position.hpp" +#include #define C_C_BOND 2.89 #define H_C_BOND 2.06 @@ -26,8 +26,8 @@ #define C_NPROTON 6 #define H_NPROTON 1 -namespace testing { - +namespace ghostfragment::hydrocarbon { +namespace { chemist::Molecule hydrocarbon(int num_carbon) { chemist::Molecule m; @@ -90,5 +90,26 @@ chemist::Molecule hydrocarbon(int num_carbon) { return m; } +} + +const auto mod_desc = R"( +Hydrocarbon Chain Generator +--------------------------- +)"; + +MODULE_CTOR(MakeHydrocarbon) { + description(mod_desc); + satisfies_property_type(); +} + +MODULE_RUN(MakeHydrocarbon) { + auto num_carbon = simde::MoleculeFromString::unwrap_inputs(inputs); -} // namespace testing + auto hc = hydrocarbon(std::stoi(num_carbon)); + + auto rv = results(); + + return simde::MoleculeFromString::wrap_results(rv, hc); +} + +} diff --git a/src/ghostfragment/hydrocarbon/makehydrocarbon.cpp b/src/ghostfragment/hydrocarbon/makehydrocarbon.cpp deleted file mode 100644 index cd461159..00000000 --- a/src/ghostfragment/hydrocarbon/makehydrocarbon.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include "hydrocarbon.hpp" -#include "hc.hpp" -#include - -namespace ghostfragment::hydrocarbon { - -using n_type = unsigned short; - -const auto mod_desc = R"( -Hydrocarbon Chain Generator ---------------------------- -)"; - -MODULE_CTOR(makehydrocarbon) { - description(mod_desc); - satisfies_property_type(); - - add_input("n") - .set_description("Number of carbons in carbon chain to generate") - .set_default(n_type(1)); -} - -MODULE_RUN(makehydrocarbon) { - auto num_carbon = inputs.at("n").value(); - - chemist::Molecule hc = hydrocarbon(int num_carbon); - - return hc; -} -} diff --git a/src/ghostfragment/hydrocarbon/position.cpp b/src/ghostfragment/hydrocarbon/position.cpp index 7280696b..af7f1b18 100644 --- a/src/ghostfragment/hydrocarbon/position.cpp +++ b/src/ghostfragment/hydrocarbon/position.cpp @@ -15,8 +15,9 @@ */ #include "position.hpp" +#include -namespace testing { +namespace ghostfragment::hydrocarbon { std::array position_carbon(const std::vector& source_coords, float carbon_bond, int num, @@ -112,4 +113,4 @@ std::array position_hydrogen(const std::vector& source_coords, return coords; } -} // namespace testing +} // namespace ghostfragment::hydrocarbon diff --git a/src/ghostfragment/hydrocarbon/position.hpp b/src/ghostfragment/hydrocarbon/position.hpp index 5f832a91..9abf59aa 100644 --- a/src/ghostfragment/hydrocarbon/position.hpp +++ b/src/ghostfragment/hydrocarbon/position.hpp @@ -16,10 +16,9 @@ #pragma once #include -#include #include -namespace testing { +namespace ghostfragment::hydrocarbon { std::array position_carbon(const std::vector& source_coords, float carbon_bond, int num, @@ -28,4 +27,4 @@ std::array position_carbon(const std::vector& source_coords, std::array position_hydrogen(const std::vector& source_coords, int flag, int num, float hydrogen_bond, float angle_deg); -} // namespace testing +} // namespace ghostfragment::hydrocarbon diff --git a/tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/hydrocarbon.hpp b/tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/hydrocarbon.hpp index 3408c743..177367b0 100644 --- a/tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/hydrocarbon.hpp +++ b/tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/hydrocarbon.hpp @@ -19,13 +19,12 @@ #include #include #include +#include #include #include namespace testing { -chemist::Molecule hydrocarbon(int num_carbon); - inline auto hydrocarbon_connectivity(std::size_t N) { // Probably a better way, but this works const auto n_atoms = hydrocarbon(N).size(); diff --git a/tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/position.cpp b/tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/position.cpp deleted file mode 100644 index 7280696b..00000000 --- a/tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/position.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2024 GhostFragment - * - * 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 "position.hpp" - -namespace testing { - -std::array position_carbon(const std::vector& source_coords, - float carbon_bond, int num, - float angle_deg) { - // Creates the pointer for positions - std::array coords{0.0, 0.0, 0.0}; - // Convert degrees to radians - float angle_rad = angle_deg * (3.14159265358979 / 180); - - // Sets the distance in each axis from the source coordinates - // X: r*sin(theta) - // Y: r*cos(theta) - // Z: 0 - coords[0] = carbon_bond * sin(angle_rad / 2); - coords[1] = carbon_bond * cos(angle_rad / 2); - coords[2] = 0; - - // If the source atom is even, the new one must go up, otherwise, - // it must go down - coords[1] *= (num % 2 == 0) ? 1 : -1; - - for(int i = 0; i < 3; i++) { coords[i] += source_coords[(3 * num) + i]; } - - return coords; -} - -std::array position_hydrogen(const std::vector& source_coords, - int flag, int num, float hydrogen_bond, - float angle_deg) { - // Creates the pointer for positions - std::array coords{0.0, 0.0, 0.0}; - // Convert degrees to radians - float angle_rad = angle_deg * (3.14159 / 180); - - // Because multiple hydrogen atoms get the same carbon atom, they need to be - // defined by which place they are taking - switch(flag) { - // Goes behind the carbon (z is negative) - case 0: - // X: 0 - // Y: r*cos(theta) - // Z: r*sin(theta) - coords[0] = 0; - coords[1] = hydrogen_bond * cos(angle_rad / 2); - coords[2] = (-1) * hydrogen_bond * sin(angle_rad / 2); - - // If the carbon atom is odd, the hydrogen must be above, otherwise, - // it must be below - coords[1] *= (num % 2 == 0) ? -1 : 1; - break; - - // Goes in front of the carbon (z is positive) - case 1: - // X: 0 - // Y: r*cos(theta) - // Z: r*sin(theta) - coords[0] = 0; - coords[1] = hydrogen_bond * cos(angle_rad / 2); - coords[2] = hydrogen_bond * sin(angle_rad / 2); - - // If the carbon atom is odd, the hydrogen must be above, otherwise, - // it must be below - coords[1] *= (num % 2 == 0) ? -1 : 1; - break; - - // Goes to the left of the first carbon - case 2: - // X: r*sin(theta) - // Y: r*cos(theta) - // Z: 0 - coords[0] = (-1) * hydrogen_bond * sin(angle_rad / 2); - coords[1] = hydrogen_bond * cos(angle_rad / 2); - coords[2] = 0; - break; - - // Goes to the right of the last carbon - case 3: - // X: r*sin(theta) - // Y: r*cos(theta) - // Z: 0 - coords[0] = hydrogen_bond * sin(angle_rad / 2); - coords[1] = hydrogen_bond * cos(angle_rad / 2); - coords[2] = 0; - - // If the last carbon is even, the hydrogen must be above, - // otherwise, it must be below - coords[1] *= (num % 2 == 0) ? 1 : -1; - break; - } - - for(int i = 0; i < 3; i++) { coords[i] += source_coords[(3 * num) + i]; } - - return coords; -} - -} // namespace testing diff --git a/tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/position.hpp b/tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/position.hpp deleted file mode 100644 index 5f832a91..00000000 --- a/tests/cxx/unit_tests/ghostfragment/testing/hydrocarbon/position.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2024 GhostFragment - * - * 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. - */ - -#pragma once -#include -#include -#include - -namespace testing { - -std::array position_carbon(const std::vector& source_coords, - float carbon_bond, int num, - float angle_deg); - -std::array position_hydrogen(const std::vector& source_coords, - int flag, int num, float hydrogen_bond, - float angle_deg); -} // namespace testing From c327c3c8a0c3129181e8a0dbdb9ca6875203b3e0 Mon Sep 17 00:00:00 2001 From: Jacob Heflin Date: Fri, 16 Aug 2024 11:57:56 -0500 Subject: [PATCH 7/7] Adjusted typing on the inputs from a tuple string to a single string, and then to an integer --- src/ghostfragment/ghostfragment.cpp | 2 +- src/ghostfragment/hydrocarbon/hydrocarbon.hpp | 2 +- src/ghostfragment/hydrocarbon/make_hydrocarbon.cpp | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ghostfragment/ghostfragment.cpp b/src/ghostfragment/ghostfragment.cpp index 2225d012..edcba93b 100644 --- a/src/ghostfragment/ghostfragment.cpp +++ b/src/ghostfragment/ghostfragment.cpp @@ -20,7 +20,7 @@ #include "screening/screening.hpp" #include "topology/topology.hpp" #include -#include "hydrocarbon/hc.hpp" +#include "hydrocarbon/hydrocarbon.hpp" namespace ghostfragment { diff --git a/src/ghostfragment/hydrocarbon/hydrocarbon.hpp b/src/ghostfragment/hydrocarbon/hydrocarbon.hpp index 819bada8..99cdc9b1 100644 --- a/src/ghostfragment/hydrocarbon/hydrocarbon.hpp +++ b/src/ghostfragment/hydrocarbon/hydrocarbon.hpp @@ -3,7 +3,7 @@ namespace ghostfragment::hydrocarbon { -chemist::Molecule hydrocarbon(int num_carbon); +// chemist::Molecule hydrocarbon(int num_carbon); DECLARE_MODULE(MakeHydrocarbon); diff --git a/src/ghostfragment/hydrocarbon/make_hydrocarbon.cpp b/src/ghostfragment/hydrocarbon/make_hydrocarbon.cpp index c502ab5a..58b9973d 100644 --- a/src/ghostfragment/hydrocarbon/make_hydrocarbon.cpp +++ b/src/ghostfragment/hydrocarbon/make_hydrocarbon.cpp @@ -15,7 +15,9 @@ */ #include "position.hpp" +#include "hydrocarbon.hpp" #include +#include #define C_C_BOND 2.89 #define H_C_BOND 2.06 @@ -103,9 +105,9 @@ MODULE_CTOR(MakeHydrocarbon) { } MODULE_RUN(MakeHydrocarbon) { - auto num_carbon = simde::MoleculeFromString::unwrap_inputs(inputs); + const std::string& num_carbon_string = std::get<0>(simde::MoleculeFromString::unwrap_inputs(inputs)); - auto hc = hydrocarbon(std::stoi(num_carbon)); + auto hc = hydrocarbon(std::stoi(num_carbon_string)); auto rv = results();