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

LAMMPS topo types and mol template format support #490

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 32 additions & 1 deletion include/chemfiles/Connectivity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <array>
#include <vector>
#include <algorithm> // IWYU pragma: keep
#include <string>

#include "chemfiles/sorted_set.hpp"
#include "chemfiles/exports.h"
Expand Down Expand Up @@ -317,7 +318,17 @@ class Connectivity final {
const sorted_set<Improper>& impropers() const;

/// Add a bond between the atoms `i` and `j`
void add_bond(size_t i, size_t j, Bond::BondOrder bond_order = Bond::UNKNOWN);
void add_bond(size_t i, size_t j, Bond::BondOrder bond_order = Bond::UNKNOWN, std::string bond_type = "");

/// Add an angle between the atoms `i`, `j` and `k`
void add_angle(size_t i, size_t j, size_t k, std::string angle_type = "");

/// Add a dihedral angle between the atoms `i`, `j`, `k` and `l`
void add_dihedral(size_t i, size_t j, size_t k, size_t l, std::string dihedral_type = "");

/// Add an improper dihedral angle between the atoms `i`, `j`, `k` and `l`
void add_improper(size_t i, size_t j, size_t k, size_t l, std::string improper_type = "");


/// Remove any bond between the atoms `i` and `j`
void remove_bond(size_t i, size_t j);
Expand All @@ -330,6 +341,18 @@ class Connectivity final {

/// Get the bond order of the bond between i and j
Bond::BondOrder bond_order(size_t i, size_t j) const;

/// Get the bond type of the bond between i and j
const std::string& bond_type(size_t i, size_t j) const;

/// Get the angle type of the angle between i, j and k
const std::string& angle_type(size_t i, size_t j, size_t k) const;

/// Get the dihedral type of the dihedral between i, j, k and l
const std::string& dihedral_type(size_t i, size_t j, size_t k, size_t l) const;

/// Get the improper type of the improper between i, j, k and l
const std::string& improper_type(size_t i, size_t j, size_t k, size_t l) const;
private:
/// Recalculate the angles and the dihedrals from the bond list
void recalculate() const;
Expand All @@ -349,6 +372,14 @@ class Connectivity final {
mutable bool uptodate_ = false;
/// Store the bond orders
std::vector<Bond::BondOrder> bond_orders_;
/// Store the bond types
mutable std::vector<std::string> bond_types_;
/// Store the angle types
mutable std::vector<std::string> angle_types_;
/// Store the dihedral types
mutable std::vector<std::string> dihedral_types_;
/// Store the improper types
mutable std::vector<std::string> improper_types_;
};

} // namespace chemfiles
Expand Down
55 changes: 53 additions & 2 deletions include/chemfiles/Frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef CHEMFILES_FRAME_HPP
#define CHEMFILES_FRAME_HPP

#include <cstddef>
#include <string>
#include <vector>

Expand Down Expand Up @@ -246,8 +247,58 @@ class CHFL_EXPORT Frame final {
/// @param bond_order the bond order of the new bond
/// @throws OutOfBounds if `atom_i` or `atom_j` are greater than `size()`
/// @throws Error if `atom_i == atom_j`, as this is an invalid bond
void add_bond(size_t atom_i, size_t atom_j, Bond::BondOrder bond_order = Bond::UNKNOWN) {
topology_.add_bond(atom_i, atom_j, bond_order);
void add_bond(size_t atom_i, size_t atom_j, Bond::BondOrder bond_order = Bond::UNKNOWN, std::string bond_type = "") {
topology_.add_bond(atom_i, atom_j, bond_order, bond_type);
}

/// Add an angle in the system, between the atoms at index `atom_i`,
/// `atom_j` and `atom_k`.
///
/// @example{frame/add_angle.cpp}
///
/// @param atom_i the index of the first atom in the angle
/// @param atom_j the index of the second atom in the angle
/// @param atom_k the index of the third atom in the angle
/// @param angle_type the angle order of the new angle
/// @throws OutOfBounds if `atom_i`, `atom_j` and `atom_k` are
/// greater than `size()`
/// @throws Error if any two indices are equal as this is an invalid angle
void add_angle(size_t atom_i, size_t atom_j, size_t atom_k, std::string angle_type = "") {
topology_.add_angle(atom_i, atom_j, atom_k, angle_type);
}

/// Add a dihedral in the system, between the atoms at index `atom_i`,
/// `atom_j`, `atom_k`, and `atom_l`.
///
/// @example{frame/add_dihedral.cpp}
///
/// @param atom_i the index of the first atom in the dihedral
/// @param atom_j the index of the second atom in the dihedral
/// @param atom_k the index of the third atom in the dihedral
/// @param atom_l the index of the forth atom in the dihedral
/// @param dihedral_type the dihedral order of the new dihedral
/// @throws OutOfBounds if `atom_i`, `atom_j` and `atom_k` are
/// greater than `size()`
/// @throws Error if any two indices are equal as this is an invalid dihedral
void add_dihedral(size_t atom_i, size_t atom_j, size_t atom_k, size_t atom_l, std::string dihedral_type = "") {
topology_.add_dihedral(atom_i, atom_j, atom_k, atom_l, dihedral_type);
}

/// Add a improper in the system, between the atoms at index `atom_i`,
/// `atom_j` and `atom_k`.
///
/// @example{frame/add_improper.cpp}
///
/// @param atom_i the index of the first atom in the improper
/// @param atom_j the index of the second atom in the improper
/// @param atom_k the index of the third atom in the improper
/// @param atom_l the index of the forth atom in the improper
/// @param improper_type the improper order of the new improper
/// @throws OutOfBounds if `atom_i`, `atom_j` and `atom_k` are
/// greater than `size()`
/// @throws Error if any two indices are equal as this is an invalid improper
void add_improper(size_t atom_i, size_t atom_j, size_t atom_k, size_t atom_l, std::string improper_type = "") {
topology_.add_improper(atom_i, atom_j, atom_k, atom_l, improper_type);
}

/// Remove a bond in the system, between the atoms at index `atom_i` and
Expand Down
99 changes: 98 additions & 1 deletion include/chemfiles/Topology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef CHEMFILES_TOPOLOGY_HPP
#define CHEMFILES_TOPOLOGY_HPP

#include <cstddef>
#include <string>
#include <vector>
#include <unordered_map>
Expand Down Expand Up @@ -113,9 +114,54 @@ class CHFL_EXPORT Topology final {
/// @param atom_i the index of the first atom in the bond
/// @param atom_j the index of the second atom in the bond
/// @param bond_order the bond order for the bond added
/// @param bond_type the bond type for the bond added
/// @throws OutOfBounds if `atom_i` or `atom_j` are greater than `size()`
/// @throws Error if `atom_i == atom_j`, as this is an invalid bond
void add_bond(size_t atom_i, size_t atom_j, Bond::BondOrder bond_order = Bond::UNKNOWN);
void add_bond(size_t atom_i, size_t atom_j, Bond::BondOrder bond_order = Bond::UNKNOWN, std::string bond_type = "");

/// Add an angle in the system, between the atoms at index `atom_i`,
/// `atom_j` and `atom_k`
///
/// @example{topology/add_angle.cpp}
///
/// @param atom_i the index of the first atom in the angle
/// @param atom_j the index of the second atom in the angle
/// @param atom_k the index of the third atom in the angle
/// @param angle_type the angle type for the angle added
/// @throws OutOfBounds if any index is greater than `size()`
/// @throws Error if any atom index is duplicate,
/// as this is an invalid angle
void add_angle(size_t atom_i, size_t atom_j, size_t atom_k, std::string angle_type = "");

/// Add a dihedral in the system, between the atoms at index `atom_i`,
/// `atom_j` and `atom_k`
///
/// @example{topology/add_dihedral.cpp}
///
/// @param atom_i the index of the first atom in the dihedral
/// @param atom_j the index of the second atom in the dihedral
/// @param atom_k the index of the third atom in the dihedral
/// @param atom_l the index of the forth atom in the dihedral
/// @param dihedral_type the dihedral type for the dihedral added
/// @throws OutOfBounds if any index is greater than `size()`
/// @throws Error if any atom index is duplicate,
/// as this is an invalid dihedral
void add_dihedral(size_t atom_i, size_t atom_j, size_t atom_k, size_t atom_l, std::string dihedral_type = "");

/// Add an improper in the system, between the atoms at index `atom_i`,
/// `atom_j` and `atom_k`
///
/// @example{topology/add_improper.cpp}
///
/// @param atom_i the index of the first atom in the improper
/// @param atom_j the index of the second atom in the improper
/// @param atom_k the index of the third atom in the improper
/// @param atom_l the index of the forth atom in the improper
/// @param improper_type the improper type for the improper added
/// @throws OutOfBounds if any index is greater than `size()`
/// @throws Error if any atom index is duplicate,
/// as this is an invalid improper
void add_improper(size_t atom_i, size_t atom_j, size_t atom_k, size_t atom_l, std::string improper_type = "");

/// Remove a bond in the system, between the atoms at index `atom_i` and
/// `atom_j`.
Expand All @@ -141,6 +187,57 @@ class CHFL_EXPORT Topology final {
/// @throws Error if no bond between `atom_i` and `atom_j` exists.
Bond::BondOrder bond_order(size_t atom_i, size_t atom_j) const;

/// Get the bond type for the given bond
///
/// If the bond does not exist, this will thrown an Error.
///
/// @example{topology/bond_type.cpp}
///
/// @param atom_i the index of the first atom in the bond
/// @param atom_j the index of the second atom in the bond
/// @throws OutOfBounds if `atom_i` or `atom_j` are greater than `size()`
/// @throws Error if no bond between `atom_i` and `atom_j` exists.
const std::string& bond_type(size_t atom_i, size_t atom_j) const;

/// Get the angle type for the given angle
///
/// If the angle does not exist, this will thrown an Error.
///
/// @example{topology/angle_type.cpp}
///
/// @param atom_i the index of the first atom in the angle
/// @param atom_j the index of the second atom in the angle
/// @param atom_k the index of the third atom in the angle
/// @throws OutOfBounds if any index is greater than `size()`
/// @throws Error if no angle exists.
const std::string& angle_type(size_t atom_i, size_t atom_j, size_t atom_k) const;

/// Get the dihedral type for the given dihedral
///
/// If the dihedral does not exist, this will thrown an Error.
///
/// @example{topology/dihedral_type.cpp}
///
/// @param atom_i the index of the first atom in the dihedral
/// @param atom_j the index of the second atom in the dihedral
/// @param atom_k the index of the third atom in the dihedral
/// @throws OutOfBounds if any index is greater than `size()`
/// @throws Error if no dihedral exists.
const std::string& dihedral_type(size_t atom_i, size_t atom_j, size_t atom_k, size_t atom_l) const;

/// Get the improper type for the given improper
///
/// If the improper does not exist, this will thrown an Error.
///
/// @example{topology/angle_type.cpp}
///
/// @param atom_i the index of the first atom in the improper
/// @param atom_j the index of the second atom in the improper
/// @param atom_k the index of the third atom in the improper
/// @throws OutOfBounds if any index is greater than `size()`
/// @throws Error if no improper exists.
const std::string& improper_type(size_t atom_i, size_t atom_j, size_t atom_k, size_t atom_l) const;

/// Get the number of atoms in the topology
///
/// @example{topology/size.cpp}
Expand Down
36 changes: 36 additions & 0 deletions include/chemfiles/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Chemfiles, a modern library for chemistry file reading and writing
// Copyright (C) Guillaume Fraux and contributors -- BSD license

// clang-format off
#ifndef CHEMFILES_CONFIG_HPP
#define CHEMFILES_CONFIG_HPP

/// An integer containing the major (x.0.0) version number
#define CHEMFILES_VERSION_MAJOR 0
/// An integer containing the minor (0.y.0) version number
#define CHEMFILES_VERSION_MINOR 11
/// An integer containing the patch (0.0.z) version number
#define CHEMFILES_VERSION_PATCH 0
/// The full version of chemfiles ("x.y.z"), as a string
#define CHEMFILES_VERSION "0.11.0-dev"

#define CHEMFILES_SIZEOF_VOID_P 8

/// Are we building code on Windows?
/* #undef CHEMFILES_WINDOWS */

// Should we include GEMMI code?
/* #undef CHFL_DISABLE_GEMMI */

/// thread_local implementation
#ifdef __cplusplus
#if 1
#define CHFL_THREAD_LOCAL thread_local
#else
#define CHFL_THREAD_LOCAL
#endif
#endif

// clang-format on

#endif
42 changes: 42 additions & 0 deletions include/chemfiles/exports.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

#ifndef CHFL_EXPORT_H
#define CHFL_EXPORT_H

#ifdef CHFL_STATIC_DEFINE
# define CHFL_EXPORT
# define CHFL_NO_EXPORT
#else
# ifndef CHFL_EXPORT
# ifdef chemfiles_EXPORTS
/* We are building this library */
# define CHFL_EXPORT
# else
/* We are using this library */
# define CHFL_EXPORT
# endif
# endif

# ifndef CHFL_NO_EXPORT
# define CHFL_NO_EXPORT
# endif
#endif

#ifndef CHFL_DEPRECATED
# define CHFL_DEPRECATED __attribute__ ((__deprecated__))
#endif

#ifndef CHFL_DEPRECATED_EXPORT
# define CHFL_DEPRECATED_EXPORT CHFL_EXPORT CHFL_DEPRECATED
#endif

#ifndef CHFL_DEPRECATED_NO_EXPORT
# define CHFL_DEPRECATED_NO_EXPORT CHFL_NO_EXPORT CHFL_DEPRECATED
#endif

#if 0 /* DEFINE_NO_DEPRECATED */
# ifndef CHFL_NO_DEPRECATED
# define CHFL_NO_DEPRECATED
# endif
#endif

#endif /* CHFL_EXPORT_H */