Skip to content
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

Initial support for constraints #481

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2633fbb
QtGui::Molecule modified
kantundpeterpan Jun 30, 2020
dfb7ae5
Remove exit calls from qtaim code
ghutchis May 8, 2020
01f3bfc
Use the data method on std::vector
cryos Jun 15, 2020
9d07a32
some cleanup
kantundpeterpan Jul 3, 2020
b5987f8
more cleanup
kantundpeterpan Jul 3, 2020
68d4426
still cleanup
kantundpeterpan Jul 3, 2020
cc62949
added Json
kantundpeterpan Jul 3, 2020
a14bb8c
cleanup
kantundpeterpan Jul 3, 2020
bc4c00f
cleanup include statements
kantundpeterpan Jul 5, 2020
ae8097d
rewrite Constraint, is now directly linked to Atoms
kantundpeterpan Jul 5, 2020
c672d4a
linked to atoms via uniqueIDs, automatic update of dialog
kantundpeterpan Jul 5, 2020
5f5ea5a
highlighting of selected Constraint
kantundpeterpan Jul 5, 2020
a751bcc
updated automatic update of constraints
kantundpeterpan Jul 6, 2020
fd75711
Update build script for Ubuntu 20.04 and 18.04
ghutchis Sep 12, 2020
f6bb1c9
fix syntax
ghutchis Sep 12, 2020
9c75e25
Added translation using Weblate (Telugu)
weblate Sep 11, 2020
a5a5208
Added translation using Weblate (Tamil)
weblate Sep 11, 2020
93d32fb
Added translation using Weblate (Romanian)
weblate Sep 11, 2020
9e9581c
Update translation files
weblate Sep 11, 2020
2da2a38
Added translation using Weblate (Croatian)
weblate Sep 11, 2020
691a196
Added translation using Weblate (Afrikaans)
weblate Sep 11, 2020
cccb3fc
Added translation using Weblate (French (Canada))
weblate Sep 11, 2020
737c8ed
Translated using Weblate (Norwegian Bokmål)
comradekingu Sep 12, 2020
b405eac
Translated using Weblate (Portuguese)
brasb Sep 12, 2020
27b7e6d
Update translation template with current strings
ghutchis Sep 12, 2020
f808cf3
Translated using Weblate (French)
VeryTastyTomato Sep 18, 2020
f4cb4e6
Translated using Weblate (French)
borisfaure Sep 21, 2020
ba7ff0c
Allow use of HDF5 >= 1.12.0
berquist Sep 6, 2020
13a7837
Translated using Weblate (Turkish)
Sep 25, 2020
d8c3f88
Translated using Weblate (Turkish)
Sep 25, 2020
256a03e
Fix minor typo in README
dvermd Sep 30, 2020
0c989e7
Add centerOfGeometry, centerOfMass and radius methods on Molecule
dvermd Sep 30, 2020
9933366
Translated using Weblate (Russian)
KovalevArtem Sep 28, 2020
f3fed6d
Translated using Weblate (Portuguese)
SantosSi Oct 1, 2020
f78b818
Translated using Weblate (Norwegian Bokmål)
comradekingu Oct 7, 2020
157bec7
Translated using Weblate (Russian)
koffevar Oct 8, 2020
fe17119
Translated using Weblate (Turkish)
Zaryob Oct 11, 2020
55fca11
Translated using Weblate (Norwegian Bokmål)
comradekingu Oct 13, 2020
43da1a8
Translated using Weblate (Portuguese (Brazil))
grsousajunior Oct 21, 2020
3507bae
Translated using Weblate (Portuguese (Brazil))
grsousajunior Oct 23, 2020
2904c0a
Translated using Weblate (Hungarian)
Oct 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions .github/workflows/build_cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ on: [push, pull_request]

env:
BUILD_TYPE: Release
QT_VERSION: 5.12.8
QT_VERSION: 5.12.9
MACOSX_DEPLOYMENT_TARGET: 10.12
CCACHE_VERSION: 3.7.7
FEATURES: -DUSE_VTK=ON -DBUILD_GPL_PLUGINS=ON
FEATURES: -DUSE_VTK=ON -DBUILD_GPL_PLUGINS=ON

jobs:
build:
Expand All @@ -22,8 +22,15 @@ jobs:
matrix:
config:
- {
name: "Ubuntu Latest GCC", artifact: "Linux.tar.gz",
os: ubuntu-latest,
name: "Ubuntu 20.04 GCC", artifact: "Ubuntu2004.tar.gz",
os: ubuntu-20.04,
cc: "gcc", cxx: "g++",
cmake_flags: "-G Ninja -DENABLE_TESTING=ON ",
cpack: "",
}
- {
name: "Ubuntu 18.04 GCC", artifact: "Ubuntu1804.tar.gz",
os: ubuntu-18.04,
cc: "gcc", cxx: "g++",
cmake_flags: "-G Ninja -DENABLE_TESTING=ON ",
cpack: "",
Expand All @@ -47,7 +54,9 @@ jobs:

- name: Install Dependencies (Linux)
if: runner.os == 'Linux'
run: sudo apt-get -qq install ninja-build libeigen3-dev libboost-all-dev libglew-dev libxml2-dev qt5-default
run: |
sudo apt-get -qq update
sudo apt-get -qq install ninja-build libeigen3-dev libboost-all-dev libglew-dev libxml2-dev qt5-default
- name: Install Dependencies (macOS)
if: runner.os == 'macOS'
run: |
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ features and goals of the Avogadro project:
![Kitware, Inc.][KitwareLogo]

Avogadro 2 is being developed as part of the [Open Chemistry][OpenChemistry]
project by an open communit, and has been developed at [Kitware][Kitware] as an
open source community project. The Avogadro 1.x series currently has more
project by an open community, and has been developed at [Kitware][Kitware] as
an open source community project. The Avogadro 1.x series currently has more
features, and can be found [here][Avogadro1]. We will be porting more features
to the Avogadro 2 code base, and making regular releases to get feedback from
the community. We are actively working to make Avogadro 2 mainline in 2018.
Expand Down
6 changes: 3 additions & 3 deletions avogadro/core/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ class Array
T* data()
{
detachWithCopy();
return &d->data[0];
return d->data.data();
}

const T* data() const { return &d->data[0]; }
const T* data() const { return d->data.data(); }

const T* constData() const { return &d->data[0]; }
const T* constData() const { return d->data.data(); }

size_t size() const { return d->data.size(); }

Expand Down
29 changes: 29 additions & 0 deletions avogadro/core/molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,35 @@ double Molecule::mass() const
return m;
}

Vector3 Molecule::centerOfGeometry() const
{
Vector3 center(0.0, 0.0, 0.0);
for (Index i = 0; i < atomCount(); ++i)
center += atom(i).position3d();
return center / atomCount();
}

Vector3 Molecule::centerOfMass() const
{
Vector3 center(0.0, 0.0, 0.0);
for (Index i = 0; i < atomCount(); ++i) {
AtomType curr_atom = atom(i);
center += (curr_atom.position3d() * Elements::mass(curr_atom.atomicNumber()));
}
center /= mass();
center /= atomCount();
return center;
}

double Molecule::radius() const
{
double radius = 0.0;
if (atomCount() > 0) {
radius = (centerOfGeometry() - atom(0).position3d()).norm();
}
return radius;
}

Array<double> Molecule::vibrationFrequencies() const
{
return m_vibrationFrequencies;
Expand Down
18 changes: 18 additions & 0 deletions avogadro/core/molecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,24 @@ class AVOGADROCORE_EXPORT Molecule
*/
double mass() const;

/**
* @return The center of geometry of the molecule obtained by summing the
* coordinates of the atoms.
*/
Vector3 centerOfGeometry() const;

/**
* @return The center of mass of the molecule obtained by summing the
* coordinates of the atoms weighted by mass.
*/
Vector3 centerOfMass() const;

/**
* @return The minimum radius of a sphere centered on centerOfGeometry
* containing all the centers of the atoms.
*/
double radius() const;

/**
* Set the basis set for the molecule, note that the molecule takes ownership
* of the object.
Expand Down
2 changes: 1 addition & 1 deletion avogadro/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if(USE_HDF5)
set(HDF5_LIBRARIES "hdf5")
endif()
include_directories(SYSTEM "${HDF5_INCLUDE_DIRS}")
add_definitions(-DAVO_USE_HDF5)
add_definitions(-DAVO_USE_HDF5 -DH5_USE_110_API)
endif()

# Add as "system headers" to avoid warnings generated by them with
Expand Down
6 changes: 3 additions & 3 deletions avogadro/qtgui/molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ namespace Avogadro {
namespace QtGui {

Molecule::Molecule(QObject* parent_)
: QObject(parent_), m_undoMolecule(new RWMolecule(*this, this))
: QObject(parent_), m_undoMolecule(new RWMolecule(*this, this)), constraints()
{
m_undoMolecule->setInteractive(true);
}

Molecule::Molecule(const Molecule& other)
: QObject(), Core::Molecule(other),
m_undoMolecule(new RWMolecule(*this, this))
m_undoMolecule(new RWMolecule(*this, this)), constraints()
{
m_undoMolecule->setInteractive(true);
// Now assign the unique ids
Expand All @@ -40,7 +40,7 @@ Molecule::Molecule(const Molecule& other)
}

Molecule::Molecule(const Core::Molecule& other)
: QObject(), Core::Molecule(other)
: QObject(), Core::Molecule(other), constraints()
{
// Now assign the unique ids
for (Index i = 0; i < atomCount(); i++)
Expand Down
8 changes: 8 additions & 0 deletions avogadro/qtgui/molecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
#include <QtCore/QObject>

namespace Avogadro {

namespace QtPlugins {
class ConstraintsModel;
}

namespace QtGui {

class Mesh;
Expand All @@ -45,6 +50,9 @@ class AVOGADROQTGUI_EXPORT Molecule
Q_OBJECT

public:

QtPlugins::ConstraintsModel* constraints;

/** Typedef for Atom class. */
typedef Core::Molecule::AtomType AtomType;

Expand Down
3 changes: 3 additions & 0 deletions avogadro/qtplugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ if(BUILD_GPL_PLUGINS)
add_subdirectory(qtaim)
endif()

#kantundpeterpan
add_subdirectory(constraints)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${original_library_output_dir}")

# Add all of the static plugins to the initialization file.
Expand Down
23 changes: 23 additions & 0 deletions avogadro/qtplugins/constraints/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
include_directories("${AvogadroLibs_SOURCE_DIR}/thirdparty")

set(constraints
constraintsextension.cpp
constraintsdialog.cpp
constraintsmodel.cpp
constraint.cpp
)

set(constraints_uis
constraintsdialog.ui
)

avogadro_plugin(ConstraintsExtension
"Constraints extension"
ExtensionPlugin
constraintsextension.h
ConstraintsExtension
"${constraints}"
"${constraints_uis}"
)

target_link_libraries(ConstraintsExtension)
168 changes: 168 additions & 0 deletions avogadro/qtplugins/constraints/constraint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#include "constraint.h"

namespace Avogadro {
namespace QtPlugins {

Constraint::Constraint(int type,
int a,
int b,
int c,
int d,
double value,
ConstraintsModel* model)
{
c_model = model;
ConstraintType = type;

//adjusting for 0 indexing
a = a-1;
b = b-1;
c = c-1;
d = d-1;

// store unique AtomIds

switch (ConstraintType)
{
case 0 ... 4:
// AtomA
Atoms << c_model->c_molecule->atomUniqueId(a);
break;

case 5:
//AtomA
Atoms << c_model->c_molecule->atomUniqueId(a);
//AtomB
Atoms << c_model->c_molecule->atomUniqueId(b);
break;

case 6:
//AtomA
Atoms << c_model->c_molecule->atomUniqueId(a);
//AtomB
Atoms << c_model->c_molecule->atomUniqueId(b);
//AtomC
Atoms << c_model->c_molecule->atomUniqueId(c);
break;

case 7:
//AtomA
Atoms << c_model->c_molecule->atomUniqueId(a);
//AtomB
Atoms << c_model->c_molecule->atomUniqueId(b);
//AtomC
Atoms << c_model->c_molecule->atomUniqueId(c);
//AtomD
Atoms << c_model->c_molecule->atomUniqueId(d);
}

ConstraintValue = value;

}

Constraint::~Constraint(){}

void Constraint::SetConstraintType(int type)
{
ConstraintType = type;
}

void Constraint::SetValue(double Value)
{
ConstraintValue = Value;
}

int Constraint::GetConstraintType() const
{
return ConstraintType;
}

double Constraint::GetConstraintValue() const
{
return ConstraintValue;
}

const Index Constraint::GetConstraintAtomA() const
{
if (Atoms.size() >= 1) //returned for all constraint types
{
return c_model->c_molecule->atomByUniqueId(Atoms[0]).index()+1;
}
else
{
return 0;
}
}

const Index Constraint::GetConstraintAtomB() const
{
if (Atoms.size() >= 2) //distance, angle and torsion constraints
{
return c_model->c_molecule->atomByUniqueId(Atoms[1]).index()+1;
}
else
{
return 0;
}
}

const Index Constraint::GetConstraintAtomC() const
{
if (Atoms.size() >= 3) //angle and torsion constraints
{
return c_model->c_molecule->atomByUniqueId(Atoms[2]).index()+1;
}
else
{
return 0;
}
}

const Index Constraint::GetConstraintAtomD() const
{
if (Atoms.size() >= 4) //torsion constraints only
{
return c_model->c_molecule->atomByUniqueId(Atoms[3]).index()+1;
}
else
{
return 0;
}
}

QJsonObject Constraint::toJson()
{
QJsonObject ConstraintJ;
ConstraintJ["type"] = GetConstraintType();
ConstraintJ["value"] = GetConstraintValue();

QJsonArray ConstraintAtoms;

switch (GetConstraintType())
{
case 0 ... 4:
ConstraintAtoms << static_cast<int>(GetConstraintAtomA());
break;
case 5:
ConstraintAtoms << static_cast<int>(GetConstraintAtomA())
<< static_cast<int>(GetConstraintAtomB());
break;
case 6:
ConstraintAtoms << static_cast<int>(GetConstraintAtomA())
<< static_cast<int>(GetConstraintAtomB())
<< static_cast<int>(GetConstraintAtomC());
break;
case 7:
ConstraintAtoms << static_cast<int>(GetConstraintAtomA())
<< static_cast<int>(GetConstraintAtomB())
<< static_cast<int>(GetConstraintAtomC())
<< static_cast<int>(GetConstraintAtomD());
break;
}

ConstraintJ.insert("atoms", ConstraintAtoms);

return ConstraintJ;
}
} //namespace QtPlugins
} //namespace Avogadro
Loading