diff --git a/corelib/src/libs/SireMM/selectorbond.h b/corelib/src/libs/SireMM/selectorbond.h index a72a71ac5..00c20df63 100644 --- a/corelib/src/libs/SireMM/selectorbond.h +++ b/corelib/src/libs/SireMM/selectorbond.h @@ -36,172 +36,171 @@ SIRE_BEGIN_HEADER namespace SireMM { -class SelectorBond; + class SelectorBond; } -SIREMM_EXPORT QDataStream& operator<<(QDataStream&, const SireMM::SelectorBond&); -SIREMM_EXPORT QDataStream& operator>>(QDataStream&, SireMM::SelectorBond&); +SIREMM_EXPORT QDataStream &operator<<(QDataStream &, const SireMM::SelectorBond &); +SIREMM_EXPORT QDataStream &operator>>(QDataStream &, SireMM::SelectorBond &); namespace SireMM { -/** This provides a Selector-style interface for multiple bonds */ -class SIREMM_EXPORT SelectorBond : - public SireBase::ConcreteProperty -{ + /** This provides a Selector-style interface for multiple bonds */ + class SIREMM_EXPORT SelectorBond : public SireBase::ConcreteProperty + { -friend QDataStream& ::operator<<(QDataStream&, const SelectorBond&); -friend QDataStream& ::operator>>(QDataStream&, SelectorBond&); + friend QDataStream & ::operator<<(QDataStream &, const SelectorBond &); + friend QDataStream & ::operator>>(QDataStream &, SelectorBond &); -public: - SelectorBond(); + public: + SelectorBond(); - SelectorBond(const Bond &bond); + SelectorBond(const Bond &bond); - SelectorBond(const SireMol::MoleculeData &molecule, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorBond(const SireMol::MoleculeData &molecule, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorBond(const MoleculeView &molecule, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorBond(const MoleculeView &molecule, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorBond(const SireMol::MoleculeData &molecule, - const SireMol::AtomID &atom, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorBond(const SireMol::MoleculeData &molecule, + const SireMol::AtomID &atom, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorBond(const SireMol::MoleculeData &molecule, - const SireMol::AtomID &atom0, const SireMol::AtomID &atom1, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorBond(const SireMol::MoleculeData &molecule, + const SireMol::AtomID &atom0, const SireMol::AtomID &atom1, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorBond(const SireMol::MoleculeView &molecule, - const SireMol::AtomID &atom, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorBond(const SireMol::MoleculeView &molecule, + const SireMol::AtomID &atom, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorBond(const SireMol::MoleculeView &molecule, - const SireMol::BondID &bond, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorBond(const SireMol::MoleculeView &molecule, + const SireMol::BondID &bond, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorBond(const SireMol::MoleculeView &molecule, - const QList &bonds, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorBond(const SireMol::MoleculeView &molecule, + const QList &bonds, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorBond(const SireMol::MoleculeView &molecule, - const SireMol::AtomID &atom0, const SireMol::AtomID &atom1, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorBond(const SireMol::MoleculeView &molecule, + const SireMol::AtomID &atom0, const SireMol::AtomID &atom1, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorBond(const SireMol::Selector &atoms, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorBond(const SireMol::Selector &atoms0, - const SireMol::Selector &atoms1, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorBond(const SireMol::Selector &atoms, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorBond(const SireMol::Selector &atoms0, + const SireMol::Selector &atoms1, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorBond(const SelectorBond &other); + SelectorBond(const SelectorBond &other); - virtual ~SelectorBond(); + virtual ~SelectorBond(); - static const char* typeName(); + static const char *typeName(); - virtual const char* what() const - { - return SelectorBond::typeName(); - } + virtual const char *what() const + { + return SelectorBond::typeName(); + } - virtual SelectorBond* clone() const - { - return new SelectorBond(*this); - } + virtual SelectorBond *clone() const + { + return new SelectorBond(*this); + } - SelectorBond& operator=(const SelectorBond &bond); + SelectorBond &operator=(const SelectorBond &bond); - bool operator==(const SelectorBond &other) const; - bool operator!=(const SelectorBond &other) const; + bool operator==(const SelectorBond &other) const; + bool operator!=(const SelectorBond &other) const; - QString toString() const; + QString toString() const; - SireMol::MolViewPtr operator[](int i) const; - SireMol::MolViewPtr operator[](const SireBase::Slice &slice) const; - SireMol::MolViewPtr operator[](const QList &idxs) const; - SireMol::MolViewPtr operator[](const SireMol::BondID &bond) const; + SireMol::MolViewPtr operator[](int i) const; + SireMol::MolViewPtr operator[](const SireBase::Slice &slice) const; + SireMol::MolViewPtr operator[](const QList &idxs) const; + SireMol::MolViewPtr operator[](const SireMol::BondID &bond) const; - Bond operator()(int i) const; - SelectorBond operator()(int i, int j) const; - SelectorBond operator()(const SireBase::Slice &slice) const; - SelectorBond operator()(const QList &idxs) const; - SelectorBond operator()(const SireMol::BondID &bond) const; + Bond operator()(int i) const; + SelectorBond operator()(int i, int j) const; + SelectorBond operator()(const SireBase::Slice &slice) const; + SelectorBond operator()(const QList &idxs) const; + SelectorBond operator()(const SireMol::BondID &bond) const; - QList toList() const; + QList toList() const; - bool isSelector() const; + bool isSelector() const; - QList IDs() const; + QList IDs() const; - SelectorBond add(const Bond &bond) const; + SelectorBond add(const Bond &bond) const; - int count() const; - int size() const; - int nViews() const; + int count() const; + int size() const; + int nViews() const; - bool isEmpty() const; - bool selectedAll() const; + bool isEmpty() const; + bool selectedAll() const; - SireMol::MolViewPtr toSelector() const; + SireMol::MolViewPtr toSelector() const; - SireMol::AtomSelection selection() const; + SireMol::AtomSelection selection() const; - SelectorBond add(const SelectorBond &other) const; + SelectorBond add(const SelectorBond &other) const; - SelectorBond intersection(const SelectorBond &other) const; + SelectorBond intersection(const SelectorBond &other) const; - SelectorBond invert(const SireBase::PropertyMap &map) const; - SelectorBond invert() const; + SelectorBond invert(const SireBase::PropertyMap &map) const; + SelectorBond invert() const; - bool hasProperty(const SireBase::PropertyName &key) const; - bool hasMetadata(const SireBase::PropertyName &key) const; - bool hasMetadata(const SireBase::PropertyName &key, - const SireBase::PropertyName &metakey) const; + bool hasProperty(const SireBase::PropertyName &key) const; + bool hasMetadata(const SireBase::PropertyName &key) const; + bool hasMetadata(const SireBase::PropertyName &key, + const SireBase::PropertyName &metakey) const; - QStringList propertyKeys() const; - QStringList metadataKeys() const; - QStringList metadataKeys(const SireBase::PropertyName &key) const; + QStringList propertyKeys() const; + QStringList metadataKeys() const; + QStringList metadataKeys(const SireBase::PropertyName &key) const; - QList properties() const; + QList properties() const; - SireMol::Mover move() const; - SireMol::Evaluator evaluate() const; + SireMol::Mover move() const; + SireMol::Evaluator evaluate() const; - QList property(const SireBase::PropertyName &key) const; - QList property(const SireBase::PropertyName &key, - const Property &default_value) const; + QList property(const SireBase::PropertyName &key) const; + QList property(const SireBase::PropertyName &key, + const Property &default_value) const; - QList lengths() const; - QList lengths(const SireBase::PropertyMap &map) const; + QList lengths() const; + QList lengths(const SireBase::PropertyMap &map) const; - QList measures() const; - QList measures(const SireBase::PropertyMap &map) const; + QList measures() const; + QList measures(const SireBase::PropertyMap &map) const; - QList potentials() const; - QList potentials(const SireBase::PropertyMap &map) const; + QList potentials() const; + QList potentials(const SireBase::PropertyMap &map) const; - QList energies() const; - QList energies( - const SireBase::PropertyMap &map) const; + QList energies() const; + QList energies( + const SireBase::PropertyMap &map) const; - SireUnits::Dimension::GeneralUnit energy() const; - SireUnits::Dimension::GeneralUnit energy( - const SireBase::PropertyMap &map) const; + SireUnits::Dimension::GeneralUnit energy() const; + SireUnits::Dimension::GeneralUnit energy( + const SireBase::PropertyMap &map) const; -protected: - /** The IDs of the bond (holding AtomIdx IDs) */ - QList bnds; -}; + protected: + /** The IDs of the bond (holding AtomIdx IDs) */ + QList bnds; + }; } // end of namespace SireMM -Q_DECLARE_METATYPE( SireMM::SelectorBond ) -Q_DECLARE_METATYPE( SireMol::Mover ) +Q_DECLARE_METATYPE(SireMM::SelectorBond) +Q_DECLARE_METATYPE(SireMol::Mover) -SIRE_EXPOSE_CLASS( SireMM::SelectorBond ) +SIRE_EXPOSE_CLASS(SireMM::SelectorBond) -SIRE_EXPOSE_ALIAS( SireMol::Mover, SireMol::Mover_SelectorBond_ ) +SIRE_EXPOSE_ALIAS(SireMol::Mover, SireMol::Mover_SelectorBond_) #ifdef SIRE_INSTANTIATE_TEMPLATES diff --git a/corelib/src/libs/SireMM/selectormbond.h b/corelib/src/libs/SireMM/selectormbond.h index 316b26980..2e278bdb6 100644 --- a/corelib/src/libs/SireMM/selectormbond.h +++ b/corelib/src/libs/SireMM/selectormbond.h @@ -33,321 +33,320 @@ #include "selectorbond.h" - SIRE_BEGIN_HEADER namespace SireMol { -class Atom; -class Residue; -class Chain; -class Segment; -class CutGroup; -class Molecule; -class MoleculeGroup; -class Molecules; -class SelectResult; - -class SelectorMol; -class EvaluatorM; + class Atom; + class Residue; + class Chain; + class Segment; + class CutGroup; + class Molecule; + class MoleculeGroup; + class Molecules; + class SelectResult; + + class SelectorMol; + class EvaluatorM; } namespace SireMM { -class SelectorMBond; + class SelectorMBond; } -SIREMM_EXPORT QDataStream& operator<<(QDataStream&, const SireMM::SelectorMBond&); -SIREMM_EXPORT QDataStream& operator>>(QDataStream&, SireMM::SelectorMBond&); +SIREMM_EXPORT QDataStream &operator<<(QDataStream &, const SireMM::SelectorMBond &); +SIREMM_EXPORT QDataStream &operator>>(QDataStream &, SireMM::SelectorMBond &); namespace SireMM { -/** Multi-molecule selector for bonds */ -class SIREMM_EXPORT SelectorMBond - : public SireBase::ConcreteProperty -{ + /** Multi-molecule selector for bonds */ + class SIREMM_EXPORT SelectorMBond + : public SireBase::ConcreteProperty + { -friend QDataStream& ::operator<<(QDataStream&, const SelectorMBond&); -friend QDataStream& ::operator>>(QDataStream&, SelectorMBond&); + friend QDataStream & ::operator<<(QDataStream &, const SelectorMBond &); + friend QDataStream & ::operator>>(QDataStream &, SelectorMBond &); -public: - typedef QList::const_iterator const_iterator; - typedef QList::const_iterator iterator; + public: + typedef QList::const_iterator const_iterator; + typedef QList::const_iterator iterator; - SelectorMBond(); - SelectorMBond(const Bond &view); + SelectorMBond(); + SelectorMBond(const Bond &view); - SelectorMBond(const SireMol::Molecules &mols, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorMBond(const SireMol::MoleculeGroup &mols, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorMBond(const SireMol::MolGroupsBase &mols, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorMBond(const SireMol::SelectResult &mols, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorMBond(const SireMol::Molecules &mols, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorMBond(const SireMol::MoleculeGroup &mols, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorMBond(const SireMol::MolGroupsBase &mols, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorMBond(const SireMol::SelectResult &mols, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorMBond(const SelectorBond &bonds); + SelectorMBond(const SelectorBond &bonds); - SelectorMBond(const SireMol::SelectorMol &mols, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorMBond(const SireMol::SelectorMol &mols, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - template - SelectorMBond(const SireMol::SelectorM &other, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + template + SelectorMBond(const SireMol::SelectorM &other, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorMBond(const SelectorMBond &bonds, const SireBase::Slice &slice); - SelectorMBond(const SelectorMBond &bonds, const QList &idxs); + SelectorMBond(const SelectorMBond &bonds, const SireBase::Slice &slice); + SelectorMBond(const SelectorMBond &bonds, const QList &idxs); - SelectorMBond(const SireMol::SelectResult &mols, - const SireMol::BondID &bond, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorMBond(const SireMol::SelectResult &mols, + const SireMol::BondID &bond, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorMBond(const SireMol::SelectorM &atoms, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorMBond(const SireMol::SelectorM &atoms, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorMBond(const SireMol::SelectorM &atoms0, - const SireMol::SelectorM &atoms1, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorMBond(const SireMol::SelectorM &atoms0, + const SireMol::SelectorM &atoms1, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorMBond(const SelectorMBond &other); + SelectorMBond(const SelectorMBond &other); - virtual ~SelectorMBond(); + virtual ~SelectorMBond(); - static const char* typeName(); + static const char *typeName(); - virtual SelectorMBond* clone() const - { - return new SelectorMBond(*this); - } + virtual SelectorMBond *clone() const + { + return new SelectorMBond(*this); + } - SelectorMBond& operator=(const SelectorMBond &other); - - bool operator==(const SelectorMBond &other) const; - bool operator!=(const SelectorMBond &other) const; - - Bond operator[](int i) const; - SelectorMBond operator[](const SireBase::Slice &slice) const; - SelectorMBond operator[](const QList &idxs) const; - SelectorMBond operator[](const SireMol::BondID &id) const; - - Bond operator()(int i) const; - SelectorMBond operator()(const SireBase::Slice &slice) const; - SelectorMBond operator()(const QList &idxs) const; - SelectorMBond operator()(const SireMol::BondID &id) const; - - QList toList() const; - SireMol::Molecules toMolecules() const; - - int count() const; - int size() const; - - void update(const SireMol::Molecules &molecules); - - SireMol::EvaluatorM evaluate() const; - - bool isSelector() const; - - SireMol::MoleculeGroup toMoleculeGroup() const; - SireMol::SelectResult toSelectResult() const; - - SireMol::Molecule molecule(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::Molecule molecule(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::Molecule molecule(const SireMol::MolID &molid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()); - - SireMol::SelectorMol molecules() const; - SireMol::SelectorMol molecules(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorMol molecules(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorMol molecules(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorMol molecules(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorMol molecules(const SireMol::MolID &molid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SireMol::Atom atom(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::Atom atom(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::Atom atom(const SireMol::AtomID &atomid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SireMol::Residue residue(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::Residue residue(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::Residue residue(const SireMol::ResID &resid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SireMol::Chain chain(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::Chain chain(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::Chain chain(const SireMol::ChainID &chainid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SireMol::Segment segment(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::Segment segment(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::Segment segment(const SireMol::SegID &segid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SireMol::CutGroup cutGroup(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::CutGroup cutGroup(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::CutGroup cutGroup(const SireMol::CGID &cgid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SireMol::SelectorM atoms() const; - SireMol::SelectorM atoms(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM atoms(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM atoms(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM atoms(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM atoms(const SireMol::AtomID &atomid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SireMol::SelectorM residues() const; - SireMol::SelectorM residues(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM residues(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM residues(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM residues(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM residues(const SireMol::ResID &resid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SireMol::SelectorM chains() const; - SireMol::SelectorM chains(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM chains(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM chains(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM chains(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM chains(const SireMol::ChainID &chainid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SireMol::SelectorM segments() const; - SireMol::SelectorM segments(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM segments(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM segments(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM segments(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM segments(const SireMol::SegID &segid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SireMol::SelectorM cutGroups() const; - SireMol::SelectorM cutGroups(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM cutGroups(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM cutGroups(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM cutGroups(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SireMol::SelectorM cutGroups(const SireMol::CGID &cgid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SelectorMBond add(const SelectorMBond &other) const; - - SelectorMBond intersection(const SelectorMBond &other) const; - - SelectorMBond invert(const SireBase::PropertyMap &map) const; - SelectorMBond invert() const; - - bool hasProperty(const SireBase::PropertyName &key) const; - bool hasMetadata(const SireBase::PropertyName &key) const; - bool hasMetadata(const SireBase::PropertyName &key, - const SireBase::PropertyName &metakey) const; - - QStringList propertyKeys() const; - QStringList metadataKeys() const; - QStringList metadataKeys(const SireBase::PropertyName &key) const; - - QList properties() const; - - QList property(const SireBase::PropertyName &key) const; - QList property(const SireBase::PropertyName &key, - const Property &default_value) const; - - QList lengths() const; - QList lengths(const SireBase::PropertyMap &map) const; - - QList measures() const; - QList measures(const SireBase::PropertyMap &map) const; - - QList potentials() const; - QList potentials(const SireBase::PropertyMap &map) const; - - QList energies() const; - QList energies( - const SireBase::PropertyMap &map) const; - - SireUnits::Dimension::GeneralUnit energy() const; - SireUnits::Dimension::GeneralUnit energy( - const SireBase::PropertyMap &map) const; - - SireMol::SelectResult search(const QString &search_string) const; - SireMol::SelectResult search(const QString &search_string, - const SireBase::PropertyMap &map) const; - - QList IDs() const; - - int nAtoms() const; - int nResidues() const; - int nChains() const; - int nSegments() const; - int nCutGroups() const; - int nMolecules() const; - - bool isEmpty() const; - - int nFrames() const; - int nFrames(const SireBase::PropertyMap &map) const; - - void loadFrame(int frame); - void saveFrame(int frame); - void saveFrame(); - void deleteFrame(int frame); - - void loadFrame(int frame, const SireBase::PropertyMap &map); - void saveFrame(int frame, const SireBase::PropertyMap &map); - void saveFrame(const SireBase::PropertyMap &map); - void deleteFrame(int frame, const SireBase::PropertyMap &map); - - const_iterator begin() const; - const_iterator end() const; - - const_iterator constBegin() const; - const_iterator constEnd() const; + SelectorMBond &operator=(const SelectorMBond &other); + + bool operator==(const SelectorMBond &other) const; + bool operator!=(const SelectorMBond &other) const; + + Bond operator[](int i) const; + SelectorMBond operator[](const SireBase::Slice &slice) const; + SelectorMBond operator[](const QList &idxs) const; + SelectorMBond operator[](const SireMol::BondID &id) const; + + Bond operator()(int i) const; + SelectorMBond operator()(const SireBase::Slice &slice) const; + SelectorMBond operator()(const QList &idxs) const; + SelectorMBond operator()(const SireMol::BondID &id) const; + + QList toList() const; + SireMol::Molecules toMolecules() const; + + int count() const; + int size() const; + + void update(const SireMol::Molecules &molecules); + + SireMol::EvaluatorM evaluate() const; + + bool isSelector() const; + + SireMol::MoleculeGroup toMoleculeGroup() const; + SireMol::SelectResult toSelectResult() const; + + SireMol::Molecule molecule(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::Molecule molecule(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::Molecule molecule(const SireMol::MolID &molid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); + + SireMol::SelectorMol molecules() const; + SireMol::SelectorMol molecules(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorMol molecules(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorMol molecules(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorMol molecules(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorMol molecules(const SireMol::MolID &molid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SireMol::Atom atom(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::Atom atom(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::Atom atom(const SireMol::AtomID &atomid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SireMol::Residue residue(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::Residue residue(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::Residue residue(const SireMol::ResID &resid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SireMol::Chain chain(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::Chain chain(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::Chain chain(const SireMol::ChainID &chainid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SireMol::Segment segment(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::Segment segment(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::Segment segment(const SireMol::SegID &segid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SireMol::CutGroup cutGroup(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::CutGroup cutGroup(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::CutGroup cutGroup(const SireMol::CGID &cgid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SireMol::SelectorM atoms() const; + SireMol::SelectorM atoms(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM atoms(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM atoms(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM atoms(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM atoms(const SireMol::AtomID &atomid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SireMol::SelectorM residues() const; + SireMol::SelectorM residues(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM residues(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM residues(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM residues(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM residues(const SireMol::ResID &resid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SireMol::SelectorM chains() const; + SireMol::SelectorM chains(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM chains(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM chains(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM chains(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM chains(const SireMol::ChainID &chainid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SireMol::SelectorM segments() const; + SireMol::SelectorM segments(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM segments(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM segments(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM segments(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM segments(const SireMol::SegID &segid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SireMol::SelectorM cutGroups() const; + SireMol::SelectorM cutGroups(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM cutGroups(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM cutGroups(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM cutGroups(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SireMol::SelectorM cutGroups(const SireMol::CGID &cgid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SelectorMBond add(const SelectorMBond &other) const; + + SelectorMBond intersection(const SelectorMBond &other) const; + + SelectorMBond invert(const SireBase::PropertyMap &map) const; + SelectorMBond invert() const; + + bool hasProperty(const SireBase::PropertyName &key) const; + bool hasMetadata(const SireBase::PropertyName &key) const; + bool hasMetadata(const SireBase::PropertyName &key, + const SireBase::PropertyName &metakey) const; + + QStringList propertyKeys() const; + QStringList metadataKeys() const; + QStringList metadataKeys(const SireBase::PropertyName &key) const; + + QList properties() const; + + QList property(const SireBase::PropertyName &key) const; + QList property(const SireBase::PropertyName &key, + const Property &default_value) const; + + QList lengths() const; + QList lengths(const SireBase::PropertyMap &map) const; + + QList measures() const; + QList measures(const SireBase::PropertyMap &map) const; + + QList potentials() const; + QList potentials(const SireBase::PropertyMap &map) const; + + QList energies() const; + QList energies( + const SireBase::PropertyMap &map) const; + + SireUnits::Dimension::GeneralUnit energy() const; + SireUnits::Dimension::GeneralUnit energy( + const SireBase::PropertyMap &map) const; + + SireMol::SelectResult search(const QString &search_string) const; + SireMol::SelectResult search(const QString &search_string, + const SireBase::PropertyMap &map) const; + + QList IDs() const; + + int nAtoms() const; + int nResidues() const; + int nChains() const; + int nSegments() const; + int nCutGroups() const; + int nMolecules() const; + + bool isEmpty() const; + + int nFrames() const; + int nFrames(const SireBase::PropertyMap &map) const; + + void loadFrame(int frame); + void saveFrame(int frame); + void saveFrame(); + void deleteFrame(int frame); + + void loadFrame(int frame, const SireBase::PropertyMap &map); + void saveFrame(int frame, const SireBase::PropertyMap &map); + void saveFrame(const SireBase::PropertyMap &map); + void deleteFrame(int frame, const SireBase::PropertyMap &map); + + const_iterator begin() const; + const_iterator end() const; + + const_iterator constBegin() const; + const_iterator constEnd() const; - virtual QString toString() const; + virtual QString toString() const; -protected: - void _append(const Bond &bond); - void _append(const SelectorBond &bonds); + protected: + void _append(const Bond &bond); + void _append(const SelectorBond &bonds); - /** The actual bonds */ - QList< SelectorBond > bnds; -}; + /** The actual bonds */ + QList bnds; + }; } // end of namespace SireMM @@ -363,22 +362,22 @@ friend QDataStream& ::operator>>(QDataStream&, SelectorMBond&); namespace SireMM { -template -SIRE_OUTOFLINE_TEMPLATE -SelectorMBond::SelectorMBond(const SireMol::SelectorM &other, - const SireBase::PropertyMap &map) - : SireBase::ConcreteProperty() -{ - if (not other.isEmpty()) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorMBond::SelectorMBond(const SireMol::SelectorM &other, + const SireBase::PropertyMap &map) + : SireBase::ConcreteProperty() { - this->bnds.reserve(other.nMolecules()); - - for (int i=0; ibnds.append(SelectorBond(other.molecule(i), map)); + this->bnds.reserve(other.nMolecules()); + + for (int i = 0; i < other.nMolecules(); ++i) + { + this->bnds.append(SelectorBond(other.molecule(i), map)); + } } } -} } // end of namespace SireMol diff --git a/corelib/src/libs/SireMaths/freeenergyaverage.cpp b/corelib/src/libs/SireMaths/freeenergyaverage.cpp index d640b6449..08c3247c8 100644 --- a/corelib/src/libs/SireMaths/freeenergyaverage.cpp +++ b/corelib/src/libs/SireMaths/freeenergyaverage.cpp @@ -52,7 +52,7 @@ static const RegisterMetaType r_avg; /** Serialise to a binary datastream */ QDataStream &operator<<(QDataStream &ds, - const FreeEnergyAverage &avg) + const FreeEnergyAverage &avg) { writeHeader(ds, r_avg, 3); @@ -60,7 +60,7 @@ QDataStream &operator<<(QDataStream &ds, sds << avg.hist << avg.is_forwards_free_energy - << static_cast(avg); + << static_cast(avg); return ds; } @@ -74,19 +74,19 @@ QDataStream &operator>>(QDataStream &ds, FreeEnergyAverage &avg) { SharedDataStream sds(ds); - sds >> avg.hist >> avg.is_forwards_free_energy >> static_cast(avg); + sds >> avg.hist >> avg.is_forwards_free_energy >> static_cast(avg); } else if (v == 2) { SharedDataStream sds(ds); - sds >> avg.hist >> static_cast(avg); + sds >> avg.hist >> static_cast(avg); avg.is_forwards_free_energy = true; } else if (v == 1) { - ds >> static_cast(avg); + ds >> static_cast(avg); avg.hist = Histogram(); avg.is_forwards_free_energy = true; } @@ -100,62 +100,74 @@ QDataStream &operator>>(QDataStream &ds, FreeEnergyAverage &avg) at room temperature (25 C) and collects statistics about the free energy using a histogram of bin width 0.5 kcal mol-1 */ FreeEnergyAverage::FreeEnergyAverage() - : ConcreteProperty( - -1.0 / (k_boltz * double(25*celsius)) ), hist(0.5) -{} + : ConcreteProperty( + -1.0 / (k_boltz.value() * double(25 * celsius))), + hist(0.5) +{ +} /** Constructor - this defaults to accumulating the average at room temperature (25 C) and collects statistics about the free energy using a histogram of bin width 0.5 kcal mol-1, specifying whether or not this is a forwards free energy */ FreeEnergyAverage::FreeEnergyAverage(bool forwards) - : ConcreteProperty( - -1.0 / (k_boltz * double(25*celsius)) ), hist(0.5), - is_forwards_free_energy(forwards) -{} + : ConcreteProperty( + -1.0 / (k_boltz.value() * double(25 * celsius))), + hist(0.5), + is_forwards_free_energy(forwards) +{ +} /** Construct an accumulator to accumulate the free energy average at the specified temperature, and to collect statistics about the free energy using a histogram of bin width 0.5 kcal mol-1 */ FreeEnergyAverage::FreeEnergyAverage(const Temperature &temperature, bool forwards) - : ConcreteProperty( - -1.0 / (k_boltz * temperature.to(kelvin)) ), hist(0.5), - is_forwards_free_energy(forwards) -{} + : ConcreteProperty( + -1.0 / (k_boltz.value() * temperature.to(kelvin))), + hist(0.5), + is_forwards_free_energy(forwards) +{ +} /** Constructor - this defaults to accumulating the average at room temperature (25 C) and collects statistics about the free energy using a histogram of the passed bin width. If the binwidth is zero, then a histogram of energies is not collected */ FreeEnergyAverage::FreeEnergyAverage(const MolarEnergy &binwidth, bool forwards) - : ConcreteProperty( - -1.0 / (k_boltz * double(25*celsius)) ), hist(binwidth.value()), - is_forwards_free_energy(forwards) -{} + : ConcreteProperty( + -1.0 / (k_boltz.value() * double(25 * celsius))), + hist(binwidth.value()), + is_forwards_free_energy(forwards) +{ +} /** Construct an accumulator to accumulate the free energy average at the specified temperature, and to collect statistics about the free energy using a histogram of passed bin width */ FreeEnergyAverage::FreeEnergyAverage(const Temperature &temperature, const MolarEnergy &binwidth, bool forwards) - : ConcreteProperty( - -1.0 / (k_boltz * temperature.to(kelvin)) ), hist(binwidth.value()), - is_forwards_free_energy(forwards) -{} + : ConcreteProperty( + -1.0 / (k_boltz.value() * temperature.to(kelvin))), + hist(binwidth.value()), + is_forwards_free_energy(forwards) +{ +} /** Copy constructor */ FreeEnergyAverage::FreeEnergyAverage(const FreeEnergyAverage &other) - : ConcreteProperty(other), - hist(other.hist), - is_forwards_free_energy(other.is_forwards_free_energy) -{} + : ConcreteProperty(other), + hist(other.hist), + is_forwards_free_energy(other.is_forwards_free_energy) +{ +} /** Destructor */ FreeEnergyAverage::~FreeEnergyAverage() -{} +{ +} /** Copy assignment operator */ -FreeEnergyAverage& FreeEnergyAverage::operator=(const FreeEnergyAverage &other) +FreeEnergyAverage &FreeEnergyAverage::operator=(const FreeEnergyAverage &other) { if (this != &other) { @@ -183,13 +195,15 @@ bool FreeEnergyAverage::operator!=(const FreeEnergyAverage &other) const } /** Combine the passed average onto this average */ -FreeEnergyAverage& FreeEnergyAverage::operator+=(const FreeEnergyAverage &other) +FreeEnergyAverage &FreeEnergyAverage::operator+=(const FreeEnergyAverage &other) { if (is_forwards_free_energy != other.is_forwards_free_energy) - throw SireError::incompatible_error( QObject::tr( - "Cannot combine a 'forwards' free energy with a 'backwards' free energy. " - "%1 vs. %2").arg(this->toString()).arg(other.toString()), - CODELOC ); + throw SireError::incompatible_error(QObject::tr( + "Cannot combine a 'forwards' free energy with a 'backwards' free energy. " + "%1 vs. %2") + .arg(this->toString()) + .arg(other.toString()), + CODELOC); ExpAverage::operator+=(other); hist += other.hist; @@ -209,11 +223,11 @@ FreeEnergyAverage FreeEnergyAverage::operator+(const FreeEnergyAverage &other) c is being accumulated */ Temperature FreeEnergyAverage::temperature() const { - return Temperature( -1.0 / (k_boltz*scaleFactor()) ); + return Temperature(-1.0 / (k_boltz.value() * scaleFactor())); } /** Return the histogram of energies */ -const Histogram& FreeEnergyAverage::histogram() const +const Histogram &FreeEnergyAverage::histogram() const { return hist; } @@ -224,23 +238,23 @@ QString FreeEnergyAverage::toString() const "stdev = %3 kcal mol-1, " "skew = %4 kcal mol-1, nSamples = %5, " "isForwardsFreeEnergy() = %6 )") - .arg(this->average()) - .arg(histogram().mean()) - .arg(histogram().standardDeviation()) - .arg(histogram().skew()) - .arg(nSamples()) - .arg(isForwardsFreeEnergy()); + .arg(this->average()) + .arg(histogram().mean()) + .arg(histogram().standardDeviation()) + .arg(histogram().skew()) + .arg(nSamples()) + .arg(isForwardsFreeEnergy()); } -const char* FreeEnergyAverage::typeName() +const char *FreeEnergyAverage::typeName() { - return QMetaType::typeName( qMetaTypeId() ); + return QMetaType::typeName(qMetaTypeId()); } /** Clear all data from the accumulator */ void FreeEnergyAverage::clear() { - hist = Histogram( hist.binWidth() ); + hist = Histogram(hist.binWidth()); ExpAverage::clear(); } @@ -266,8 +280,8 @@ bool FreeEnergyAverage::isBackwardsFreeEnergy() const /** Return the Taylor series expansion estimate the difference in free energy */ double FreeEnergyAverage::taylorExpansion() const { - double dg = hist.mean() - 0.5*k_boltz*temperature() * - ( hist.meanOfSquares() - (hist.mean()*hist.mean()) ); + double dg = hist.mean() - 0.5 * k_boltz.value() * temperature() * + (hist.meanOfSquares() - (hist.mean() * hist.mean())); if (not is_forwards_free_energy) dg *= -1; @@ -288,7 +302,6 @@ double FreeEnergyAverage::fepFreeEnergy() const return dg; } - /** Return the average free energy. Note that if this is a backwards free energy, then this will return the negative (so that it is easy to combine backwards and forwards values) */ @@ -322,7 +335,7 @@ FreeEnergyAverage::operator double() const static const RegisterMetaType r_bennetts; QDataStream &operator<<(QDataStream &ds, - const BennettsFreeEnergyAverage &bennetts) + const BennettsFreeEnergyAverage &bennetts) { writeHeader(ds, r_bennetts, 2); @@ -330,7 +343,7 @@ QDataStream &operator<<(QDataStream &ds, sds << bennetts.bennetts_avg << bennetts.bennetts_avg2 << bennetts.const_offset - << static_cast(bennetts); + << static_cast(bennetts); return ds; } @@ -343,9 +356,7 @@ QDataStream &operator>>(QDataStream &ds, BennettsFreeEnergyAverage &bennetts) { SharedDataStream sds(ds); - sds >> bennetts.bennetts_avg >> bennetts.bennetts_avg2 - >> bennetts.const_offset - >> static_cast(bennetts); + sds >> bennetts.bennetts_avg >> bennetts.bennetts_avg2 >> bennetts.const_offset >> static_cast(bennetts); } else if (v == 1) { @@ -353,11 +364,9 @@ QDataStream &operator>>(QDataStream &ds, BennettsFreeEnergyAverage &bennetts) MolarEnergy tmp; - sds >> bennetts.bennetts_avg >> tmp - >> bennetts.bennetts_avg2 >> tmp - >> static_cast(bennetts); + sds >> bennetts.bennetts_avg >> tmp >> bennetts.bennetts_avg2 >> tmp >> static_cast(bennetts); - bennetts.const_offset = 0*kcal_per_mol; + bennetts.const_offset = 0 * kcal_per_mol; } else throw version_error(v, "1,2", r_bennetts, CODELOC); @@ -367,45 +376,51 @@ QDataStream &operator>>(QDataStream &ds, BennettsFreeEnergyAverage &bennetts) /** Constructor */ BennettsFreeEnergyAverage::BennettsFreeEnergyAverage() - : ConcreteProperty(), - bennetts_avg(0), bennetts_avg2(0), const_offset(0) -{} + : ConcreteProperty(), + bennetts_avg(0), bennetts_avg2(0), const_offset(0) +{ +} /** Constructor, specifying whether or not this is a forwards free energy */ BennettsFreeEnergyAverage::BennettsFreeEnergyAverage(bool forwards) - : ConcreteProperty(forwards), - bennetts_avg(0), bennetts_avg2(0), const_offset(0) -{} + : ConcreteProperty(forwards), + bennetts_avg(0), bennetts_avg2(0), const_offset(0) +{ +} /** Construct the average at the specified temperature */ BennettsFreeEnergyAverage::BennettsFreeEnergyAverage(const Temperature &temperature, bool forwards) - : ConcreteProperty(temperature,forwards), - bennetts_avg(0), bennetts_avg2(0), const_offset(0) -{} + : ConcreteProperty(temperature, forwards), + bennetts_avg(0), bennetts_avg2(0), const_offset(0) +{ +} /** Construct, specifying the value of any constant offset for the ratio (C value) and the temperature */ BennettsFreeEnergyAverage::BennettsFreeEnergyAverage(const MolarEnergy &constant, const Temperature &temperature, bool forwards) - : ConcreteProperty(temperature,forwards), - bennetts_avg(0), bennetts_avg2(0), const_offset(constant) -{} + : ConcreteProperty(temperature, forwards), + bennetts_avg(0), bennetts_avg2(0), const_offset(constant) +{ +} /** Construct, specifying the constant offset for the ratio (C value) */ BennettsFreeEnergyAverage::BennettsFreeEnergyAverage(const MolarEnergy &constant, bool forwards) - : ConcreteProperty(forwards), - bennetts_avg(0), bennetts_avg2(0), const_offset(constant) -{} + : ConcreteProperty(forwards), + bennetts_avg(0), bennetts_avg2(0), const_offset(constant) +{ +} /** Construct at the specified temperature, using a histogram of the specified bin width */ BennettsFreeEnergyAverage::BennettsFreeEnergyAverage(const Temperature &temperature, const MolarEnergy &binwidth, bool forwards) - : ConcreteProperty(temperature,binwidth,forwards), - bennetts_avg(0), bennetts_avg2(0), const_offset(0) -{} + : ConcreteProperty(temperature, binwidth, forwards), + bennetts_avg(0), bennetts_avg2(0), const_offset(0) +{ +} /** Construct at the specified temperature, using the specificed constant (C value), using a histogram of the specified bin width */ @@ -413,23 +428,26 @@ BennettsFreeEnergyAverage::BennettsFreeEnergyAverage(const MolarEnergy &constant const Temperature &temperature, const MolarEnergy &binwidth, bool forwards) - : ConcreteProperty(temperature,binwidth,forwards), - bennetts_avg(0), bennetts_avg2(0), const_offset(constant) -{} + : ConcreteProperty(temperature, binwidth, forwards), + bennetts_avg(0), bennetts_avg2(0), const_offset(constant) +{ +} /** Copy constructor */ BennettsFreeEnergyAverage::BennettsFreeEnergyAverage(const BennettsFreeEnergyAverage &other) - : ConcreteProperty(other), - bennetts_avg(other.bennetts_avg), bennetts_avg2(other.bennetts_avg2), - const_offset(other.const_offset) -{} + : ConcreteProperty(other), + bennetts_avg(other.bennetts_avg), bennetts_avg2(other.bennetts_avg2), + const_offset(other.const_offset) +{ +} /** Destructor */ BennettsFreeEnergyAverage::~BennettsFreeEnergyAverage() -{} +{ +} /** Copy assignment operator */ -BennettsFreeEnergyAverage& +BennettsFreeEnergyAverage & BennettsFreeEnergyAverage::operator=(const BennettsFreeEnergyAverage &other) { if (this != &other) @@ -475,19 +493,24 @@ MolarEnergy BennettsFreeEnergyAverage::constant() const } /** Self-addition operator */ -BennettsFreeEnergyAverage& +BennettsFreeEnergyAverage & BennettsFreeEnergyAverage::operator+=(const BennettsFreeEnergyAverage &other) { if (isForwardsRatio() != other.isForwardsRatio()) - throw SireError::incompatible_error( QObject::tr( - "Cannot combine a 'forwards' free energy with a 'backwards' free energy. " - "%1 vs. %2").arg(this->toString()).arg(other.toString()), - CODELOC ); + throw SireError::incompatible_error(QObject::tr( + "Cannot combine a 'forwards' free energy with a 'backwards' free energy. " + "%1 vs. %2") + .arg(this->toString()) + .arg(other.toString()), + CODELOC); if (this->constant() != other.constant()) - throw SireError::incompatible_error( QObject::tr( - "Cannot combine Bennetts averages that have different constant offsets! " - "%1 vs. %2").arg(this->toString()).arg(other.toString()), CODELOC ); + throw SireError::incompatible_error(QObject::tr( + "Cannot combine Bennetts averages that have different constant offsets! " + "%1 vs. %2") + .arg(this->toString()) + .arg(other.toString()), + CODELOC); double nsteps = nSamples() + other.nSamples(); @@ -511,9 +534,9 @@ BennettsFreeEnergyAverage::operator+(const BennettsFreeEnergyAverage &other) con return ret; } -const char* BennettsFreeEnergyAverage::typeName() +const char *BennettsFreeEnergyAverage::typeName() { - return QMetaType::typeName( qMetaTypeId() ); + return QMetaType::typeName(qMetaTypeId()); } QString BennettsFreeEnergyAverage::toString() const @@ -523,15 +546,15 @@ QString BennettsFreeEnergyAverage::toString() const "stderr = %5 kcal mol-1, " "skew = %6 kcal mol-1, nSamples = %7, constant() = %8 kcal mol-1 " "isForwardsRatio() = %9 )") - .arg(this->fepFreeEnergy()) - .arg(histogram().mean()) - .arg(bennettsRatio()) - .arg(bennettsStandardError(90)) - .arg(histogram().standardError()) - .arg(histogram().skew()) - .arg(nSamples()) - .arg(constant().to(kcal_per_mol)) - .arg(isForwardsRatio()); + .arg(this->fepFreeEnergy()) + .arg(histogram().mean()) + .arg(bennettsRatio()) + .arg(bennettsStandardError(90)) + .arg(histogram().standardError()) + .arg(histogram().skew()) + .arg(nSamples()) + .arg(constant().to(kcal_per_mol)) + .arg(isForwardsRatio()); } /** Clear this accumulator */ @@ -559,15 +582,15 @@ void BennettsFreeEnergyAverage::accumulate(double value) if (isForwardsRatio()) { - val = 1.0 / (1.0 + std::exp(-this->scaleFactor()*(value-const_offset.value()))); + val = 1.0 / (1.0 + std::exp(-this->scaleFactor() * (value - const_offset.value()))); } else { - val = 1.0 / (1.0 + std::exp(-this->scaleFactor()*(value+const_offset.value()))); + val = 1.0 / (1.0 + std::exp(-this->scaleFactor() * (value + const_offset.value()))); } bennetts_avg = my_ratio * bennetts_avg + other_ratio * val; - bennetts_avg2 = my_ratio * bennetts_avg2 + other_ratio * (val*val); + bennetts_avg2 = my_ratio * bennetts_avg2 + other_ratio * (val * val); FreeEnergyAverage::accumulate(value); } @@ -586,6 +609,6 @@ double BennettsFreeEnergyAverage::bennettsStandardError(double level) const if (this->nSamples() == 0) return 0; - double stdev = std::sqrt( bennetts_avg2 - pow_2(bennetts_avg) ); - return Histogram::tValue(this->nSamples(),level) * stdev / std::sqrt(this->nSamples()); + double stdev = std::sqrt(bennetts_avg2 - pow_2(bennetts_avg)); + return Histogram::tValue(this->nSamples(), level) * stdev / std::sqrt(this->nSamples()); } diff --git a/corelib/src/libs/SireMol/selector.hpp b/corelib/src/libs/SireMol/selector.hpp index df3c57ff3..9c5afb257 100644 --- a/corelib/src/libs/SireMol/selector.hpp +++ b/corelib/src/libs/SireMol/selector.hpp @@ -53,1806 +53,1948 @@ SIRE_BEGIN_HEADER namespace SireMol { -template -class Selector; + template + class Selector; + + template + class SelectorM; } -template -SIREMOL_EXPORT QDataStream& operator<<(QDataStream&, const SireMol::Selector&); +template +SIREMOL_EXPORT QDataStream &operator<<(QDataStream &, const SireMol::Selector &); -template -SIREMOL_EXPORT QDataStream& operator>>(QDataStream&, SireMol::Selector&); +template +SIREMOL_EXPORT QDataStream &operator>>(QDataStream &, SireMol::Selector &); namespace SireMol { -class MoleculeData; - -namespace detail -{ + class MoleculeData; -SIREMOL_EXPORT bool has_property(const Atom*, const MoleculeData &moldata, - const PropertyName &key); -SIREMOL_EXPORT bool has_property(const Chain*, const MoleculeData &moldata, - const PropertyName &key); -SIREMOL_EXPORT bool has_property(const CutGroup*, const MoleculeData &moldata, - const PropertyName &key); -SIREMOL_EXPORT bool has_property(const Residue*, const MoleculeData &moldata, - const PropertyName &key); -SIREMOL_EXPORT bool has_property(const Segment*, const MoleculeData &moldata, - const PropertyName &key); - -SIREMOL_EXPORT bool has_metadata(const Atom*, const MoleculeData &moldata, - const PropertyName &metakey); -SIREMOL_EXPORT bool has_metadata(const Chain*, const MoleculeData &moldata, - const PropertyName &metakey); -SIREMOL_EXPORT bool has_metadata(const CutGroup*, const MoleculeData &moldata, - const PropertyName &metakey); -SIREMOL_EXPORT bool has_metadata(const Residue*, const MoleculeData &moldata, - const PropertyName &metakey); -SIREMOL_EXPORT bool has_metadata(const Segment*, const MoleculeData &moldata, - const PropertyName &metakey); - -SIREMOL_EXPORT bool has_metadata(const Atom*, const MoleculeData &moldata, - const PropertyName &key, const PropertyName &metakey); -SIREMOL_EXPORT bool has_metadata(const Chain*, const MoleculeData &moldata, - const PropertyName &key, const PropertyName &metakey); -SIREMOL_EXPORT bool has_metadata(const CutGroup*, const MoleculeData &moldata, - const PropertyName &key, const PropertyName &metakey); -SIREMOL_EXPORT bool has_metadata(const Residue*, const MoleculeData &moldata, - const PropertyName &key, const PropertyName &metakey); -SIREMOL_EXPORT bool has_metadata(const Segment*, const MoleculeData &moldata, - const PropertyName &key, const PropertyName &metakey); - -} // end of namespace detail - -/** This template class provides a way to manipulate the selection - of parts of a a molecule, e.g. Selector provides a - MoleculeView that has a user-configurable view of an - arbitrary set of atoms. This class is used by the code - whenever multiple groups from within the same molecule - are returned, e.g. when returning all residues that - have a particular name - - @author Christopher Woods -*/ -template -class SIREMOL_EXPORT Selector : public SireBase::ConcreteProperty,MoleculeView> -{ + namespace detail + { -friend SIREMOL_EXPORT QDataStream& ::operator<<<>(QDataStream&, const Selector&); -friend SIREMOL_EXPORT QDataStream& ::operator>><>(QDataStream&, Selector&); + SIREMOL_EXPORT bool has_property(const Atom *, const MoleculeData &moldata, + const PropertyName &key); + SIREMOL_EXPORT bool has_property(const Chain *, const MoleculeData &moldata, + const PropertyName &key); + SIREMOL_EXPORT bool has_property(const CutGroup *, const MoleculeData &moldata, + const PropertyName &key); + SIREMOL_EXPORT bool has_property(const Residue *, const MoleculeData &moldata, + const PropertyName &key); + SIREMOL_EXPORT bool has_property(const Segment *, const MoleculeData &moldata, + const PropertyName &key); + + SIREMOL_EXPORT bool has_metadata(const Atom *, const MoleculeData &moldata, + const PropertyName &metakey); + SIREMOL_EXPORT bool has_metadata(const Chain *, const MoleculeData &moldata, + const PropertyName &metakey); + SIREMOL_EXPORT bool has_metadata(const CutGroup *, const MoleculeData &moldata, + const PropertyName &metakey); + SIREMOL_EXPORT bool has_metadata(const Residue *, const MoleculeData &moldata, + const PropertyName &metakey); + SIREMOL_EXPORT bool has_metadata(const Segment *, const MoleculeData &moldata, + const PropertyName &metakey); + + SIREMOL_EXPORT bool has_metadata(const Atom *, const MoleculeData &moldata, + const PropertyName &key, const PropertyName &metakey); + SIREMOL_EXPORT bool has_metadata(const Chain *, const MoleculeData &moldata, + const PropertyName &key, const PropertyName &metakey); + SIREMOL_EXPORT bool has_metadata(const CutGroup *, const MoleculeData &moldata, + const PropertyName &key, const PropertyName &metakey); + SIREMOL_EXPORT bool has_metadata(const Residue *, const MoleculeData &moldata, + const PropertyName &key, const PropertyName &metakey); + SIREMOL_EXPORT bool has_metadata(const Segment *, const MoleculeData &moldata, + const PropertyName &key, const PropertyName &metakey); + + } // end of namespace detail + + /** This template class provides a way to manipulate the selection + of parts of a a molecule, e.g. Selector provides a + MoleculeView that has a user-configurable view of an + arbitrary set of atoms. This class is used by the code + whenever multiple groups from within the same molecule + are returned, e.g. when returning all residues that + have a particular name + + @author Christopher Woods + */ + template + class SIREMOL_EXPORT Selector : public SireBase::ConcreteProperty, MoleculeView> + { -public: - Selector(); + friend SIREMOL_EXPORT QDataStream & ::operator<< <>(QDataStream &, const Selector &); + friend SIREMOL_EXPORT QDataStream & ::operator>><>(QDataStream &, Selector &); - Selector(const T &view); + public: + Selector(); - Selector(const MoleculeData &moldata); + Selector(const T &view); - Selector(const MoleculeData &moldata, - const AtomSelection &selected_atoms); + Selector(const MoleculeData &moldata); - Selector(const MoleculeData &moldata, const typename T::ID &viewid); + Selector(const MoleculeData &moldata, + const AtomSelection &selected_atoms); - Selector(const MoleculeData &moldata, const QList &idxs); + Selector(const MoleculeData &moldata, const typename T::ID &viewid); - Selector(const Selector &other); + Selector(const MoleculeData &moldata, const QList &idxs); - ~Selector(); + Selector(const Selector &other); - Selector& operator=(const Selector &other); - Selector& operator=(const T &view); + ~Selector(); - static const char* typeName(); + Selector &operator=(const Selector &other); + Selector &operator=(const T &view); - Selector* clone() const; + static const char *typeName(); - QList IDs() const; - QList indexes() const; - QList names() const; - QList numbers() const; + Selector *clone() const; - bool operator==(const Selector &other) const; - bool operator!=(const Selector &other) const; + QList IDs() const; + QList indexes() const; + QList names() const; + QList numbers() const; - Selector operator+(const Selector &other) const; - Selector operator-(const Selector &other) const; + bool operator==(const Selector &other) const; + bool operator!=(const Selector &other) const; - Selector operator+(const typename T::ID &id) const; - Selector operator-(const typename T::ID &id) const; + Selector operator+(const Selector &other) const; + Selector operator-(const Selector &other) const; - Selector operator+(const T &view) const; - Selector operator-(const T &view) const; + Selector operator+(const typename T::ID &id) const; + Selector operator-(const typename T::ID &id) const; - int nViews() const; + Selector operator+(const T &view) const; + Selector operator-(const T &view) const; - MolViewPtr operator[](int i) const; - MolViewPtr operator[](const QString &name) const; - MolViewPtr operator[](const SireBase::Slice &slice) const; - MolViewPtr operator[](const QList &idxs) const; - MolViewPtr operator[](const AtomID &atomid) const; - MolViewPtr operator[](const ResID &resid) const; - MolViewPtr operator[](const CGID &cgid) const; - MolViewPtr operator[](const ChainID &chainid) const; - MolViewPtr operator[](const SegID &segid) const; - MolViewPtr operator[](const SireID::Index &idx) const; + int nViews() const; - T operator()(int i) const; - T operator()(const SireID::Index &idx) const; - Selector operator()(int i, int j) const; - Selector operator()(const SireBase::Slice &slice) const; - Selector operator()(const QList &idxs) const; - Selector operator()(const AtomID &atomid) const; - Selector operator()(const ResID &resid) const; - Selector operator()(const CGID &cgid) const; - Selector operator()(const ChainID &chainid) const; - Selector operator()(const SegID &segid) const; + MolViewPtr operator[](int i) const; + MolViewPtr operator[](const QString &name) const; + MolViewPtr operator[](const SireBase::Slice &slice) const; + MolViewPtr operator[](const QList &idxs) const; + MolViewPtr operator[](const AtomID &atomid) const; + MolViewPtr operator[](const ResID &resid) const; + MolViewPtr operator[](const CGID &cgid) const; + MolViewPtr operator[](const ChainID &chainid) const; + MolViewPtr operator[](const SegID &segid) const; + MolViewPtr operator[](const SireID::Index &idx) const; - typename T::Index index(int i) const; + T operator()(int i) const; + T operator()(const SireID::Index &idx) const; + Selector operator()(int i, int j) const; + Selector operator()(const SireBase::Slice &slice) const; + Selector operator()(const QList &idxs) const; + Selector operator()(const AtomID &atomid) const; + Selector operator()(const ResID &resid) const; + Selector operator()(const CGID &cgid) const; + Selector operator()(const ChainID &chainid) const; + Selector operator()(const SegID &segid) const; - MolViewPtr toSelector() const; - QList toList() const; + typename T::Index index(int i) const; - Molecules toMolecules() const; + MolViewPtr toSelector() const; + QList toList() const; - QString toString() const; + Molecules toMolecules() const; - bool isEmpty() const; - bool selectedAll() const; + QString toString() const; - bool isSelector() const; + bool isEmpty() const; + bool selectedAll() const; - Selector add(const Selector &other) const; - Selector add(const T &view) const; - Selector add(const typename T::ID &id) const; + bool isSelector() const; - Selector subtract(const Selector &other) const; - Selector subtract(const T &view) const; - Selector subtract(const typename T::ID &id) const; + Selector add(const Selector &other) const; + Selector add(const T &view) const; + Selector add(const typename T::ID &id) const; - Selector intersection(const Selector &other) const; - Selector intersection(const T &view) const; - Selector intersection(const typename T::ID &id) const; + Selector subtract(const Selector &other) const; + Selector subtract(const T &view) const; + Selector subtract(const typename T::ID &id) const; - Selector invert() const; + Selector intersection(const Selector &other) const; + Selector intersection(const T &view) const; + Selector intersection(const typename T::ID &id) const; - bool intersects(const Selector &other) const; - bool intersects(const T &view) const; - bool intersects(const typename T::ID &id) const; + Selector invert() const; - bool contains(const Selector &other) const; - bool contains(const T &view) const; - bool contains(const typename T::ID &id) const; + QList find(const T &view) const; + QList find(const Selector &views) const; + QList find(const SelectorM &views) const; - AtomSelection selection() const; - AtomSelection selection(int i) const; - AtomSelection selection(int i, int j) const; + bool intersects(const Selector &other) const; + bool intersects(const T &view) const; + bool intersects(const typename T::ID &id) const; - Mover< Selector > move() const; - Mover< Selector > move(int i) const; - Mover< Selector > move(int i, int j) const; + bool contains(const Selector &other) const; + bool contains(const T &view) const; + bool contains(const typename T::ID &id) const; - Evaluator evaluate() const; - Evaluator evaluate(int i) const; - Evaluator evaluate(int i, int j) const; + AtomSelection selection() const; + AtomSelection selection(int i) const; + AtomSelection selection(int i, int j) const; - Selector selector() const; - Selector selector(int i) const; - Selector selector(int i, int j) const; + Mover> move() const; + Mover> move(int i) const; + Mover> move(int i, int j) const; - bool hasProperty(const PropertyName &key) const; - bool hasMetadata(const PropertyName &metakey) const; - bool hasMetadata(const PropertyName &key, - const PropertyName &metakey) const; + Evaluator evaluate() const; + Evaluator evaluate(int i) const; + Evaluator evaluate(int i, int j) const; - QStringList propertyKeys() const; - QStringList metadataKeys() const; - QStringList metadataKeys(const PropertyName &key) const; + Selector selector() const; + Selector selector(int i) const; + Selector selector(int i, int j) const; - template - QList property(const PropertyName &key) const; + bool hasProperty(const PropertyName &key) const; + bool hasMetadata(const PropertyName &metakey) const; + bool hasMetadata(const PropertyName &key, + const PropertyName &metakey) const; - template - QList metadata(const PropertyName &metakey) const; + QStringList propertyKeys() const; + QStringList metadataKeys() const; + QStringList metadataKeys(const PropertyName &key) const; - template - QList metadata(const PropertyName &key, - const PropertyName &metakey) const; + template + QList property(const PropertyName &key) const; -protected: - template - void setProperty(const QString &key, const QList &values); + template + QList metadata(const PropertyName &metakey) const; - template - void setMetadata(const QString &metakey, const QList &values); + template + QList metadata(const PropertyName &key, + const PropertyName &metakey) const; - template - void setMetadata(const QString &key, const QString &metakey, - const QList &values); + protected: + template + void setProperty(const QString &key, const QList &values); - template - void setProperty(const QString &key, const V &value); + template + void setMetadata(const QString &metakey, const QList &values); - template - void setMetadata(const QString &metakey, V &value); + template + void setMetadata(const QString &key, const QString &metakey, + const QList &values); - template - void setMetadata(const QString &key, const QString &metakey, - const V &value); + template + void setProperty(const QString &key, const V &value); -private: - /** The list of indicies of the selected parts - of the molecule. This is empty if the entire - molecule is selected - */ - QList idxs; -}; + template + void setMetadata(const QString &metakey, V &value); -#ifndef SIRE_SKIP_INLINE_FUNCTIONS + template + void setMetadata(const QString &key, const QString &metakey, + const V &value); -/** Null constructor */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector::Selector() : SireBase::ConcreteProperty,MoleculeView>() -{} + private: + /** The list of indicies of the selected parts + of the molecule. This is empty if the entire + molecule is selected + */ + QList idxs; + }; -/** Construct the set of all groups for the molecule whose - data is in 'moldata' */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector::Selector(const MoleculeData &moldata) - : SireBase::ConcreteProperty,MoleculeView>(moldata) -{} +#ifndef SIRE_SKIP_INLINE_FUNCTIONS -/** Construct the set of all groups for the molecule whose data is in 'moldata' - and with the specfied groups selected */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector::Selector(const MoleculeData &moldata, - const QList &indexes) - : SireBase::ConcreteProperty,MoleculeView>(moldata) -{ - int n = detail::getCount(moldata.info()); + /** Null constructor */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector::Selector() : SireBase::ConcreteProperty, MoleculeView>() + { + } - //ensure all of the indexes are valid! - foreach (typename T::Index idx, indexes) + /** Construct the set of all groups for the molecule whose + data is in 'moldata' */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector::Selector(const MoleculeData &moldata) + : SireBase::ConcreteProperty, MoleculeView>(moldata) { - idx.map(n); } - idxs = indexes; -} + /** Construct the set of all groups for the molecule whose data is in 'moldata' + and with the specfied groups selected */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector::Selector(const MoleculeData &moldata, + const QList &indexes) + : SireBase::ConcreteProperty, MoleculeView>(moldata) + { + int n = detail::getCount(moldata.info()); -/** Construct the set of all groups that contain at least - one of the atoms selected in 'selected_atoms' + // ensure all of the indexes are valid! + foreach (typename T::Index idx, indexes) + { + idx.map(n); + } - \throw SireError::incompatible_error -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector::Selector(const MoleculeData &moldata, - const AtomSelection &selected_atoms) - : SireBase::ConcreteProperty,MoleculeView>(moldata) -{ - if (selected_atoms.selectedNone()) - { - this->operator=(Selector()); + idxs = indexes; } - else if (not selected_atoms.selectedAll()) + + /** Construct the set of all groups that contain at least + one of the atoms selected in 'selected_atoms' + + \throw SireError::incompatible_error + */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector::Selector(const MoleculeData &moldata, + const AtomSelection &selected_atoms) + : SireBase::ConcreteProperty, MoleculeView>(moldata) { - idxs = detail::getAll(moldata.info(), selected_atoms); + if (selected_atoms.selectedNone()) + { + this->operator=(Selector()); + } + else if (not selected_atoms.selectedAll()) + { + idxs = detail::getAll(moldata.info(), selected_atoms); + } } -} -/** Construct the set that contains only the view 'view' */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector::Selector(const T &view) - : SireBase::ConcreteProperty,MoleculeView>(view) -{ - idxs.append(view.index()); -} + /** Construct the set that contains only the view 'view' */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector::Selector(const T &view) + : SireBase::ConcreteProperty, MoleculeView>(view) + { + idxs.append(view.index()); + } -/** Construct the set of parts that match the ID 'id' from the - molecule whose data is in 'moldata' - - \throw SireMol::missing_atom - \throw SireMol::missing_residue - \throw SireMol::missing_chain - \throw SireMol::missing_segment - \throw SireMol::missing_cutgroup - \throw SireError::invalid_index -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector::Selector(const MoleculeData &moldata, - const typename T::ID &viewid) - : SireBase::ConcreteProperty,MoleculeView>(moldata) -{ - idxs = viewid.map(moldata.info()); + /** Construct the set of parts that match the ID 'id' from the + molecule whose data is in 'moldata' - if (idxs.count() == detail::getCount(moldata.info())) + \throw SireMol::missing_atom + \throw SireMol::missing_residue + \throw SireMol::missing_chain + \throw SireMol::missing_segment + \throw SireMol::missing_cutgroup + \throw SireError::invalid_index + */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector::Selector(const MoleculeData &moldata, + const typename T::ID &viewid) + : SireBase::ConcreteProperty, MoleculeView>(moldata) { - idxs.clear(); + idxs = viewid.map(moldata.info()); + + if (idxs.count() == detail::getCount(moldata.info())) + { + idxs.clear(); + } + else if (idxs.isEmpty()) + { + this->operator=(Selector()); + } } - else if (idxs.isEmpty()) + + /** Copy constructor */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector::Selector(const Selector &other) + : SireBase::ConcreteProperty, MoleculeView>(other), + idxs(other.idxs) { - this->operator=(Selector()); } -} -/** Copy constructor */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector::Selector(const Selector &other) - : SireBase::ConcreteProperty,MoleculeView>(other), - idxs(other.idxs) -{} + /** Destructor */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector::~Selector() + { + } -/** Destructor */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector::~Selector() -{} + /** Copy assignment operator */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector & + Selector::operator=(const Selector &other) + { + MoleculeView::operator=(other); + idxs = other.idxs; -/** Copy assignment operator */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector& Selector::operator=(const Selector &other) -{ - MoleculeView::operator=(other); - idxs = other.idxs; + return *this; + } - return *this; -} + /** Copy so that this contains just 'view' */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector & + Selector::operator=(const T &view) + { + MoleculeView::operator=(view); -/** Copy so that this contains just 'view' */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector& Selector::operator=(const T &view) -{ - MoleculeView::operator=(view); + idxs.clear(); + idxs.append(view.index()); - idxs.clear(); - idxs.append(view.index()); + return *this; + } - return *this; -} + /** Comparison operator */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::operator==(const Selector &other) const + { + return idxs == other.idxs and MoleculeView::operator==(other); + } -/** Comparison operator */ -template -SIRE_OUTOFLINE_TEMPLATE -bool Selector::operator==(const Selector &other) const -{ - return idxs == other.idxs and MoleculeView::operator==(other); -} + /** Comparison operator */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::operator!=(const Selector &other) const + { + return idxs != other.idxs or MoleculeView::operator!=(other); + } -/** Comparison operator */ -template -SIRE_OUTOFLINE_TEMPLATE -bool Selector::operator!=(const Selector &other) const -{ - return idxs != other.idxs or MoleculeView::operator!=(other); -} + template + SIRE_OUTOFLINE_TEMPLATE const char *Selector::typeName() + { + return QMetaType::typeName(qMetaTypeId>()); + } -template -SIRE_OUTOFLINE_TEMPLATE -const char* Selector::typeName() -{ - return QMetaType::typeName( qMetaTypeId< Selector >() ); -} + template + SIRE_OUTOFLINE_TEMPLATE + Selector * + Selector::clone() const + { + return new Selector(*this); + } -template -SIRE_OUTOFLINE_TEMPLATE -Selector* Selector::clone() const -{ - return new Selector(*this); -} + /** Return the IDs of all of the items in this selector, in the + * order they appear in the selector + */ + template + SIRE_OUTOFLINE_TEMPLATE + QList + Selector::IDs() const + { + if (this->isEmpty()) + return QList(); -/** Return the IDs of all of the items in this selector, in the - * order they appear in the selector - */ -template -SIRE_OUTOFLINE_TEMPLATE -QList Selector::IDs() const -{ - if (this->isEmpty()) - return QList(); + else if (this->selectedAll()) + { + const int n = detail::getCount(this->data().info()); - else if (this->selectedAll()) - { - const int n = detail::getCount(this->data().info()); + QList ret; + ret.reserve(n); - QList ret; - ret.reserve(n); + for (int i = 0; i < n; ++i) + { + ret.append(typename T::Index(i)); + } - for (int i=0; i + SIRE_OUTOFLINE_TEMPLATE + QList + Selector::indexes() const + { + return this->IDs(); } - else - return idxs; -} -/** Return the indexes of all of the items in this selector, in the - * order they appear in the selector - */ -template -SIRE_OUTOFLINE_TEMPLATE -QList Selector::indexes() const -{ - return this->IDs(); -} + /** Return the names of all of the items in this selector, in the + * order they appear in the selector + */ + template + SIRE_OUTOFLINE_TEMPLATE + QList + Selector::names() const + { + auto indexes = this->IDs(); -/** Return the names of all of the items in this selector, in the - * order they appear in the selector - */ -template -SIRE_OUTOFLINE_TEMPLATE -QList Selector::names() const -{ - auto indexes = this->IDs(); + QList n; + n.reserve(indexes.count()); - QList n; - n.reserve(indexes.count()); + const auto &molinfo = this->data().info(); - const auto &molinfo = this->data().info(); + for (const auto &index : indexes) + { + n.append(molinfo.name(index)); + } - for (const auto &index : indexes) - { - n.append( molinfo.name(index) ); + return n; } - return n; -} + /** Return the numbers of all of the items in this selector, in the + * order they appear in the selector + */ + template + SIRE_OUTOFLINE_TEMPLATE + QList + Selector::numbers() const + { + auto indexes = this->IDs(); -/** Return the numbers of all of the items in this selector, in the - * order they appear in the selector - */ -template -SIRE_OUTOFLINE_TEMPLATE -QList Selector::numbers() const -{ - auto indexes = this->IDs(); + QList n; + n.reserve(indexes.count()); - QList n; - n.reserve(indexes.count()); + const auto &molinfo = this->data().info(); - const auto &molinfo = this->data().info(); + for (const auto &index : indexes) + { + n.append(molinfo.number(index)); + } - for (const auto &index : indexes) - { - n.append( molinfo.number(index) ); + return n; } - return n; -} - -/** Return whether this set is empty */ -template -SIRE_OUTOFLINE_TEMPLATE -bool Selector::isEmpty() const -{ - return this->data().isEmpty(); -} + /** Return whether this set is empty */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::isEmpty() const + { + return this->data().isEmpty(); + } -/** Return whether or not the entire molecule is selected */ -template -SIRE_OUTOFLINE_TEMPLATE -bool Selector::selectedAll() const -{ - // have no indexes if we have selected all of the molecule - if (not this->isEmpty()) + /** Return whether or not the entire molecule is selected */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::selectedAll() const { - if (idxs.isEmpty()) - return true; + // have no indexes if we have selected all of the molecule + if (not this->isEmpty()) + { + if (idxs.isEmpty()) + return true; - const int n = detail::getCount(this->data().info()); + const int n = detail::getCount(this->data().info()); - if (idxs.count() >= n) - { - auto s = _list_to_set(idxs); - return s.count() == n; + if (idxs.count() >= n) + { + auto s = _list_to_set(idxs); + return s.count() == n; + } } - } - return false; -} - -/** Return whether or not this is a Selector object */ -template -SIRE_OUTOFLINE_TEMPLATE -bool Selector::isSelector() const -{ - return true; -} + return false; + } -/** Return a string representation of this selector */ -template -SIRE_OUTOFLINE_TEMPLATE -QString Selector::toString() const -{ - if (this->isEmpty()) + /** Return whether or not this is a Selector object */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::isSelector() const { - return QObject::tr("Selector<%1>::empty").arg(T::typeName()); + return true; } - else - { - QStringList parts; - if (this->size() <= 10) + /** Return a string representation of this selector */ + template + SIRE_OUTOFLINE_TEMPLATE + QString + Selector::toString() const + { + if (this->isEmpty()) { - for (int i=0; isize(); ++i) - { - parts.append(QString("%1: %2").arg(i).arg(this->operator()(i).toString())); - } + return QObject::tr("Selector<%1>::empty").arg(T::typeName()); } else { - for (int i=0; i<5; ++i) + QStringList parts; + + if (this->size() <= 10) { - parts.append(QString("%1: %2").arg(i).arg(this->operator()(i).toString())); + for (int i = 0; i < this->size(); ++i) + { + parts.append(QString("%1: %2").arg(i).arg(this->operator()(i).toString())); + } } + else + { + for (int i = 0; i < 5; ++i) + { + parts.append(QString("%1: %2").arg(i).arg(this->operator()(i).toString())); + } - parts.append("..."); + parts.append("..."); - for (int i=this->size()-5; isize(); ++i) - { - parts.append(QString("%1: %3").arg(i).arg(this->operator()(i).toString())); + for (int i = this->size() - 5; i < this->size(); ++i) + { + parts.append(QString("%1: %3").arg(i).arg(this->operator()(i).toString())); + } } - } - return QObject::tr( "Selector<%1>( size=%2\n%3\n)") - .arg(T::typeName()).arg(this->count()) - .arg(parts.join("\n")); + return QObject::tr("Selector<%1>( size=%2\n%3\n)") + .arg(T::typeName()) + .arg(this->count()) + .arg(parts.join("\n")); + } } -} -/** Return the sum of this selection with 'other' - items from - 'other' are appended to this set only if they are not already - in this set + /** Return the sum of this selection with 'other' - items from + 'other' are appended to this set only if they are not already + in this set - \throw SireError::incompatible_error -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::add(const Selector &other) const -{ - if (this->selectedAll()) + \throw SireError::incompatible_error + */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::add(const Selector &other) const { - if (other.isEmpty()) + if (this->selectedAll()) + { + if (other.isEmpty()) + return *this; + + MoleculeView::assertSameMolecule(other); + return *this; + } + else if (other.selectedAll()) + { + if (this->isEmpty()) + return other; - MoleculeView::assertSameMolecule(other); + MoleculeView::assertSameMolecule(other); - return *this; - } - else if (other.selectedAll()) - { - if (this->isEmpty()) - return other; + // do this so that we always use the version from the left hand molecule + Selector ret(*this); + ret.idxs.clear(); + return ret; + } MoleculeView::assertSameMolecule(other); - // do this so that we always use the version from the left hand molecule Selector ret(*this); - ret.idxs.clear(); + + if (ret.idxs.isEmpty()) + { + // expand the indexes + const int n = detail::getCount(this->data().info()); + ret.idxs.reserve(n); + + for (int i = 0; i < n; ++i) + { + ret.idxs.append(typename T::Index(i)); + } + } + + if (other.idxs.isEmpty()) + { + const int n = detail::getCount(this->data().info()); + ret.idxs.reserve(ret.idxs.count() + n); + + for (int i = 0; i < n; ++i) + { + ret.idxs.append(typename T::Index(i)); + } + } + else + { + ret.idxs.reserve(ret.idxs.count() + other.idxs.count()); + + for (typename T::Index idx : other.idxs) + { + ret.idxs.append(idx); + } + } + return ret; } - MoleculeView::assertSameMolecule(other); + /** Return the view 'view' to this set */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::add(const T &view) const + { + return this->add(Selector(view)); + } - Selector ret(*this); + /** Return the set that has all views that match the ID 'id' + added - if (ret.idxs.isEmpty()) + \throw SireMol::missing_atom + \throw SireMol::missing_residue + \throw SireMol::missing_chain + \throw SireMol::missing_segment + \throw SireMol::missing_cutgroup + \throw SireError::invalid_index + */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::add(const typename T::ID &id) const { - //expand the indexes - const int n = detail::getCount(this->data().info()); - ret.idxs.reserve(n); + return this->operator+(Selector(this->data(), id)); + } + + /** Subtract all of the views in 'other' from this set - for (int i=0; i + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::subtract(const Selector &other) const + { + if (this->isEmpty()) + return Selector(); + else if (other.selectedAll()) { - ret.idxs.append(typename T::Index(i)); + MoleculeView::assertSameMolecule(other); + return Selector(); } - } - if (other.idxs.isEmpty()) - { + Selector ret(*this); + const int n = detail::getCount(this->data().info()); - ret.idxs.reserve(ret.idxs.count() + n); - for (int i=0; i(); } - } - return ret; -} + return ret; + } -/** Return the view 'view' to this set */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::add(const T &view) const -{ - return this->add(Selector(view)); -} + /** Remove the view 'view' from this set -/** Return the set that has all views that match the ID 'id' - added - - \throw SireMol::missing_atom - \throw SireMol::missing_residue - \throw SireMol::missing_chain - \throw SireMol::missing_segment - \throw SireMol::missing_cutgroup - \throw SireError::invalid_index -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::add(const typename T::ID &id) const -{ - return this->operator+(Selector(this->data(), id)); -} + \throw SireError::incompatible_error + */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::subtract(const T &view) const + { + return this->subtract(Selector(view)); + } -/** Subtract all of the views in 'other' from this set + /** Subtract all of the views that match the ID 'id' from + this set - \throw SireError::incompatible_error -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::subtract(const Selector &other) const -{ - if (this->isEmpty()) - return Selector(); - else if (other.selectedAll()) + \throw SireMol::missing_atom + \throw SireMol::missing_residue + \throw SireMol::missing_chain + \throw SireMol::missing_segment + \throw SireMol::missing_cutgroup + \throw SireError::invalid_index + */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::subtract(const typename T::ID &id) const { - MoleculeView::assertSameMolecule(other); - return Selector(); + return this->subtract(Selector(this->data(), id)); } - Selector ret(*this); + /** Syntactic sugar for add() */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator+(const Selector &other) const + { + return this->add(other); + } - const int n = detail::getCount(this->data().info()); + /** Syntactic sugar for subtract() */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator-(const Selector &other) const + { + return this->subtract(other); + } - if (ret.idxs.isEmpty()) + /** Syntactic sugar for add() */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator+(const typename T::ID &id) const { + return this->add(id); + } - for (int i=0; i + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator-(const typename T::ID &id) const + { + return this->subtract(id); } - foreach (typename T::Index idx, other.idxs) + /** Syntactic sugar for add() */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator+(const T &view) const { - ret.idxs.removeAll(idx); + return this->add(view); + } - if (ret.idxs.isEmpty()) - return Selector(); + /** Syntactic sugar for subtract() */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator-(const T &view) const + { + return this->subtract(view); } - return ret; -} + /** Return the ith view in this set (this supports negative indexing!) -/** Remove the view 'view' from this set + \throw SireError::invalid_index + */ + template + SIRE_OUTOFLINE_TEMPLATE + MolViewPtr + Selector::operator[](int i) const + { + return this->operator()(i); + } - \throw SireError::incompatible_error -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::subtract(const T &view) const -{ - return this->subtract(Selector(view)); -} - -/** Subtract all of the views that match the ID 'id' from - this set - - \throw SireMol::missing_atom - \throw SireMol::missing_residue - \throw SireMol::missing_chain - \throw SireMol::missing_segment - \throw SireMol::missing_cutgroup - \throw SireError::invalid_index -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::subtract(const typename T::ID &id) const -{ - return this->subtract(Selector(this->data(), id)); -} - -/** Syntactic sugar for add() */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator+(const Selector &other) const -{ - return this->add(other); -} - -/** Syntactic sugar for subtract() */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator-(const Selector &other) const -{ - return this->subtract(other); -} - -/** Syntactic sugar for add() */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator+(const typename T::ID &id) const -{ - return this->add(id); -} - -/** Syntactic sugar for subtract() */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator-(const typename T::ID &id) const -{ - return this->subtract(id); -} - -/** Syntactic sugar for add() */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator+(const T &view) const -{ - return this->add(view); -} - -/** Syntactic sugar for subtract() */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator-(const T &view) const -{ - return this->subtract(view); -} - -/** Return the ith view in this set (this supports negative indexing!) - - \throw SireError::invalid_index -*/ -template -SIRE_OUTOFLINE_TEMPLATE -MolViewPtr Selector::operator[](int i) const -{ - return this->operator()(i); -} - -template -SIRE_OUTOFLINE_TEMPLATE -MolViewPtr Selector::operator[](const QString &name) const -{ - auto match = this->operator()(AtomName(name)); + template + SIRE_OUTOFLINE_TEMPLATE + MolViewPtr + Selector::operator[](const QString &name) const + { + auto match = this->operator()(AtomName(name)); - if (match.nAtoms() == 1) - return match(0); - else - return match; -} + if (match.nAtoms() == 1) + return match(0); + else + return match; + } -template -SIRE_OUTOFLINE_TEMPLATE -MolViewPtr Selector::operator[](const SireBase::Slice &slice) const -{ - return this->operator()(slice); -} + template + SIRE_OUTOFLINE_TEMPLATE + MolViewPtr + Selector::operator[](const SireBase::Slice &slice) const + { + return this->operator()(slice); + } -template -SIRE_OUTOFLINE_TEMPLATE -MolViewPtr Selector::operator[](const QList &idxs) const -{ - return this->operator()(idxs); -} + template + SIRE_OUTOFLINE_TEMPLATE + MolViewPtr + Selector::operator[](const QList &idxs) const + { + return this->operator()(idxs); + } -/** Exposing MoleculeView::operator[] */ -template -SIRE_OUTOFLINE_TEMPLATE -MolViewPtr Selector::operator[](const AtomID &atom) const -{ - auto match = this->operator()(atom); + /** Exposing MoleculeView::operator[] */ + template + SIRE_OUTOFLINE_TEMPLATE + MolViewPtr + Selector::operator[](const AtomID &atom) const + { + auto match = this->operator()(atom); - if (match.nAtoms() == 1) - return match(0); - else - return match; -} + if (match.nAtoms() == 1) + return match(0); + else + return match; + } -/** Exposing MoleculeView::operator[] */ -template -SIRE_OUTOFLINE_TEMPLATE -MolViewPtr Selector::operator[](const ResID &res) const -{ - auto match = this->operator()(res); + /** Exposing MoleculeView::operator[] */ + template + SIRE_OUTOFLINE_TEMPLATE + MolViewPtr + Selector::operator[](const ResID &res) const + { + auto match = this->operator()(res); - if (match.nResidues() == 1) - return match(0); - else - return match; -} + if (match.nResidues() == 1) + return match(0); + else + return match; + } -/** Exposing MoleculeView::operator[] */ -template -SIRE_OUTOFLINE_TEMPLATE -MolViewPtr Selector::operator[](const CGID &cg) const -{ - auto match = this->operator()(cg); + /** Exposing MoleculeView::operator[] */ + template + SIRE_OUTOFLINE_TEMPLATE + MolViewPtr + Selector::operator[](const CGID &cg) const + { + auto match = this->operator()(cg); - if (match.nCutGroups() == 1) - return match(0); - else - return match; -} + if (match.nCutGroups() == 1) + return match(0); + else + return match; + } -/** Exposing MoleculeView::operator[] */ -template -SIRE_OUTOFLINE_TEMPLATE -MolViewPtr Selector::operator[](const ChainID &chain) const -{ - auto match = this->operator()(chain); + /** Exposing MoleculeView::operator[] */ + template + SIRE_OUTOFLINE_TEMPLATE + MolViewPtr + Selector::operator[](const ChainID &chain) const + { + auto match = this->operator()(chain); - if (match.nChains() == 1) - return match(0); - else - return match; -} + if (match.nChains() == 1) + return match(0); + else + return match; + } -/** Exposing MoleculeView::operator[] */ -template -SIRE_OUTOFLINE_TEMPLATE -MolViewPtr Selector::operator[](const SegID &seg) const -{ - auto match = this->operator()(seg); + /** Exposing MoleculeView::operator[] */ + template + SIRE_OUTOFLINE_TEMPLATE + MolViewPtr + Selector::operator[](const SegID &seg) const + { + auto match = this->operator()(seg); - if (match.nSegments() == 1) - return match(0); - else - return match; -} + if (match.nSegments() == 1) + return match(0); + else + return match; + } -/** Exposing MoleculeView::operator[] */ -template -SIRE_OUTOFLINE_TEMPLATE -MolViewPtr Selector::operator[](const SireID::Index &idx) const -{ - return this->operator()(idx.value()); -} + /** Exposing MoleculeView::operator[] */ + template + SIRE_OUTOFLINE_TEMPLATE + MolViewPtr + Selector::operator[](const SireID::Index &idx) const + { + return this->operator()(idx.value()); + } -/** Return the index of the ith view in this set (this supports negative indexing) + /** Return the index of the ith view in this set (this supports negative indexing) - \throw SireError::invalid_index -*/ -template -SIRE_OUTOFLINE_TEMPLATE -typename T::Index Selector::index(int i) const -{ - if (not this->isEmpty()) + \throw SireError::invalid_index + */ + template + SIRE_OUTOFLINE_TEMPLATE + typename T::Index + Selector::index(int i) const { - if (idxs.isEmpty()) - { - const int n = detail::getCount(this->data().info()); - return typename T::Index(SireID::Index(i).map(n)); - } - else + if (not this->isEmpty()) { - return idxs.at( SireID::Index(i).map(idxs.count())); + if (idxs.isEmpty()) + { + const int n = detail::getCount(this->data().info()); + return typename T::Index(SireID::Index(i).map(n)); + } + else + { + return idxs.at(SireID::Index(i).map(idxs.count())); + } } - } - - return typename T::Index(SireID::Index(i).map(0)); -} -/** Return the ith view in this set (this supports negative indexing!) + return typename T::Index(SireID::Index(i).map(0)); + } - \throw SireError::invalid_index -*/ -template -SIRE_OUTOFLINE_TEMPLATE -T Selector::operator()(int i) const -{ - return T(this->data(), this->index(i)); -} + /** Return the ith view in this set (this supports negative indexing!) -/** Return the range of views from index i to j in this set. This - supports negative indexing, and also, if j is less then i, then - the order of views in the returned set is reversed + \throw SireError::invalid_index + */ + template + SIRE_OUTOFLINE_TEMPLATE + T + Selector::operator()(int i) const + { + return T(this->data(), this->index(i)); + } - \throw SireError::invalid_index -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator()(int i, int j) const -{ - if (this->isEmpty()) - // raise an index exception - i = SireID::Index(i).map(0); + /** Return the range of views from index i to j in this set. This + supports negative indexing, and also, if j is less then i, then + the order of views in the returned set is reversed - if (this->idxs.isEmpty()) + \throw SireError::invalid_index + */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator()(int i, int j) const { - const int n = detail::getCount(this->data().info()); + if (this->isEmpty()) + // raise an index exception + i = SireID::Index(i).map(0); - i = SireID::Index(i).map(n); - j = SireID::Index(j).map(n); + if (this->idxs.isEmpty()) + { + const int n = detail::getCount(this->data().info()); - Selector ret(*this); - ret.idxs.clear(); + i = SireID::Index(i).map(n); + j = SireID::Index(j).map(n); - if (i <= j) - { - if (i == 0 and j == n-1) - // selected all - return ret; + Selector ret(*this); + ret.idxs.clear(); - for ( ; i<=j; ++i) + if (i <= j) { - ret.idxs.append(typename T::Index(i)); + if (i == 0 and j == n - 1) + // selected all + return ret; + + for (; i <= j; ++i) + { + ret.idxs.append(typename T::Index(i)); + } + } + else + { + if (i == n - 1 and j == 0) + // selected all + return ret; + + for (; i >= j; --i) + { + ret.idxs.append(typename T::Index(i)); + } } + + return ret; } else { - if (i == n-1 and j == 0) - // selected all - return ret; + i = SireID::Index(i).map(idxs.count()); + j = SireID::Index(j).map(idxs.count()); + + Selector ret(*this); + ret.idxs.clear(); - for ( ; i >= j; --i) + if (i <= j) { - ret.idxs.append(typename T::Index(i)); + for (; i <= j; ++i) + { + ret.idxs.append(this->idxs.at(i)); + } + } + else + { + for (; i >= j; --i) + { + ret.idxs.append(this->idxs.at(i)); + } } - } - return ret; + return ret; + } } - else - { - i = SireID::Index(i).map(idxs.count()); - j = SireID::Index(j).map(idxs.count()); - Selector ret(*this); - ret.idxs.clear(); + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator()(const SireBase::Slice &slice) const + { + if (this->isEmpty()) + // raise an exception + slice.begin(0); - if (i <= j) + if (this->idxs.isEmpty()) { - for ( ; i<=j; ++i) + const int n = detail::getCount(this->data().info()); + + Selector ret(*this); + ret.idxs.clear(); + + for (auto it = slice.begin(n); not it.atEnd(); it.next()) { - ret.idxs.append(this->idxs.at(i)); + ret.idxs.append(typename T::Index(it.value())); } + + return ret; } else { - for ( ; i >= j; --i) + Selector ret(*this); + ret.idxs.clear(); + + for (auto it = slice.begin(this->idxs.count()); + not it.atEnd(); it.next()) { - ret.idxs.append(this->idxs.at(i)); + ret.idxs.append(this->idxs.at(it.value())); } - } - return ret; + return ret; + } } -} -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator()(const SireBase::Slice &slice) const -{ - if (this->isEmpty()) - //raise an exception - slice.begin(0); + /** Return the range of views from whose indicies are in idxs in this set. - if (this->idxs.isEmpty()) + \throw SireError::invalid_index + */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator()(const QList &idxs) const { - const int n = detail::getCount(this->data().info()); - - Selector ret(*this); - ret.idxs.clear(); + if (idxs.isEmpty()) + return Selector(); - for (auto it = slice.begin(n); not it.atEnd(); it.next()) + else if (this->isEmpty()) { - ret.idxs.append(typename T::Index(it.value())); + // raise an exception + SireID::Index(idxs.at(0)).map(0); + return Selector(); } - - return ret; - } - else - { - Selector ret(*this); - ret.idxs.clear(); - - for (auto it = slice.begin(this->idxs.count()); - not it.atEnd(); it.next()) + else if (this->idxs.isEmpty()) { - ret.idxs.append(this->idxs.at(it.value())); - } - - return ret; - } -} + Selector ret(*this); + ret.idxs.clear(); -/** Return the range of views from whose indicies are in idxs in this set. + const int n = detail::getCount(this->data().info()); - \throw SireError::invalid_index -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator()(const QList &idxs) const -{ - if (idxs.isEmpty()) - return Selector(); + QSet seen; - else if (this->isEmpty()) - { - //raise an exception - SireID::Index(idxs.at(0)).map(0); - return Selector(); - } - else if (this->idxs.isEmpty()) - { - Selector ret(*this); - ret.idxs.clear(); + for (const auto &idx : idxs) + { + typename T::Index index(SireID::Index(idx).map(n)); - const int n = detail::getCount(this->data().info()); + if (not seen.contains(index)) + { + ret.idxs.append(index); + seen.insert(index); + } + } - QSet seen; + if (ret.idxs.count() >= n) + ret.idxs.clear(); - for (const auto &idx : idxs) + return ret; + } + else { - typename T::Index index(SireID::Index(idx).map(n)); + Selector ret(*this); + ret.idxs.clear(); - if (not seen.contains(index)) + for (const auto &idx : idxs) { + auto index = this->idxs.at(SireID::Index(idx).map(this->idxs.count())); ret.idxs.append(index); - seen.insert(index); } - } - - if (ret.idxs.count() >= n) - ret.idxs.clear(); - - return ret; - } - else - { - Selector ret(*this); - ret.idxs.clear(); - for (const auto &idx : idxs) - { - auto index = this->idxs.at(SireID::Index(idx).map(this->idxs.count())); - ret.idxs.append(index); + return ret; } - - return ret; } -} - -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator()(const AtomID &atomid) const -{ - return this->atoms(atomid); -} -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator()(const ResID &resid) const -{ - return this->residues(resid); -} + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator()(const AtomID &atomid) const + { + return this->atoms(atomid); + } -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator()(const CGID &cgid) const -{ - return this->cutGroups(cgid); -} + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator()(const ResID &resid) const + { + return this->residues(resid); + } -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator()(const ChainID &chainid) const -{ - return this->chains(chainid); -} + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator()(const CGID &cgid) const + { + return this->cutGroups(cgid); + } -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::operator()(const SegID &segid) const -{ - return this->segments(segid); -} + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator()(const ChainID &chainid) const + { + return this->chains(chainid); + } -template -SIRE_OUTOFLINE_TEMPLATE -MolViewPtr Selector::toSelector() const -{ - return MolViewPtr(*this); -} + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::operator()(const SegID &segid) const + { + return this->segments(segid); + } -template -SIRE_OUTOFLINE_TEMPLATE -Molecules Selector::toMolecules() const -{ - return Molecules( ViewsOfMol(*this) ); -} + template + SIRE_OUTOFLINE_TEMPLATE + MolViewPtr + Selector::toSelector() const + { + return MolViewPtr(*this); + } -template -SIRE_OUTOFLINE_TEMPLATE -QList Selector::toList() const -{ - QList l; + template + SIRE_OUTOFLINE_TEMPLATE + Molecules + Selector::toMolecules() const + { + return Molecules(ViewsOfMol(*this)); + } - if (not this->isEmpty()) + template + SIRE_OUTOFLINE_TEMPLATE + QList + Selector::toList() const { - if (idxs.isEmpty()) + QList l; + + if (not this->isEmpty()) { - //return the entire molecule - const auto& d = this->data(); + if (idxs.isEmpty()) + { + // return the entire molecule + const auto &d = this->data(); - const int n = detail::getCount(d.info()); - l.reserve(n); + const int n = detail::getCount(d.info()); + l.reserve(n); - for (int i=0; idata(); + const auto &d = this->data(); - for (const auto &idx : idxs) - { - l.append(MolViewPtr(new T(d, idx))); + for (const auto &idx : idxs) + { + l.append(MolViewPtr(new T(d, idx))); + } } } + + return l; } - return l; -} + template + SIRE_OUTOFLINE_TEMPLATE + T + Selector::operator()(const SireID::Index &idx) const + { + return this->operator()(idx.value()); + } -template -SIRE_OUTOFLINE_TEMPLATE -T Selector::operator()(const SireID::Index &idx) const -{ - return this->operator()(idx.value()); -} - -/** Return the number of views in this set */ -template -SIRE_OUTOFLINE_TEMPLATE -int Selector::nViews() const -{ - if (this->isEmpty()) - return 0; - else if (this->selectedAll()) - return detail::getCount(this->data().info()); - else - return this->idxs.count(); -} + /** Return the number of views in this set */ + template + SIRE_OUTOFLINE_TEMPLATE int Selector::nViews() const + { + if (this->isEmpty()) + return 0; + else if (this->selectedAll()) + return detail::getCount(this->data().info()); + else + return this->idxs.count(); + } -template -SIRE_INLINE_TEMPLATE -QSet _list_to_set(const QList &vals) -{ - #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + template + SIRE_INLINE_TEMPLATE + QSet + _list_to_set(const QList &vals) + { +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) return QSet(vals.constBegin(), vals.constEnd()); - #else +#else return vals.toSet(); - #endif -} +#endif + } -/** Return the intersection of this set with 'other' - the - views in both sets are returned, in the order that they - appear in this set + /** Return the intersection of this set with 'other' - the + views in both sets are returned, in the order that they + appear in this set - \throw SireError::incompatible_error -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::intersection(const Selector &other) const -{ - if (this->isEmpty() or other.isEmpty()) - return Selector(); - - else if (this->selectedAll()) + \throw SireError::incompatible_error + */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::intersection(const Selector &other) const { - MoleculeView::assertSameMolecule(other); - Selector ret(*this); - ret.idxs = other.idxs; - return ret; + if (this->isEmpty() or other.isEmpty()) + return Selector(); + + else if (this->selectedAll()) + { + MoleculeView::assertSameMolecule(other); + Selector ret(*this); + ret.idxs = other.idxs; + return ret; + } + else if (other.selectedAll()) + { + MoleculeView::assertSameMolecule(other); + return *this; + } + else + { + MoleculeView::assertSameMolecule(other); + + Selector ret(*this); + ret.idxs.clear(); + + auto this_idxs = this->idxs; + auto other_idxs = other.idxs; + + const int n = detail::getCount(this->data().info()); + + if (this_idxs.isEmpty()) + { + this_idxs.reserve(n); + for (int i = 0; i < n; ++i) + { + this_idxs.append(typename T::Index(i)); + } + } + + if (other_idxs.isEmpty()) + { + other_idxs.reserve(n); + for (int i = 0; i < n; ++i) + { + other_idxs.append(typename T::Index(i)); + } + } + + auto seen = _list_to_set(other_idxs); + + for (const auto &idx : this_idxs) + { + if (seen.contains(idx)) + ret.idxs.append(idx); + } + + if (ret.idxs.isEmpty()) + { + return Selector(); + } + + return ret; + } } - else if (other.selectedAll()) + + /** Return the intersection of this set with 'view' + + \throw SireError::incompatible_error + */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::intersection(const T &view) const { - MoleculeView::assertSameMolecule(other); - return *this; + return this->intersection(Selector(view)); } - else - { - MoleculeView::assertSameMolecule(other); - Selector ret(*this); - ret.idxs.clear(); + /** Return the intersection of this set with the views identified + by the ID 'id' - auto this_idxs = this->idxs; - auto other_idxs = other.idxs; + \throw SireMol::missing_atom + \throw SireMol::missing_residue + \throw SireMol::missing_chain + \throw SireMol::missing_segment + \throw SireMol::missing_cutgroup + \throw SireError::invalid_index + */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::intersection(const typename T::ID &id) const + { + return this->intersection(Selector(this->data(), id)); + } - const int n = detail::getCount(this->data().info()); + /** Return the index in this collection of the view that + * matches 'view'. This returns an empty list if the + * view is not in this collection + */ + template + SIRE_OUTOFLINE_TEMPLATE + QList + Selector::find(const T &view) const + { + QList matches; - if (this_idxs.isEmpty()) + if (MoleculeView::isSameMolecule(view)) { - this_idxs.reserve(n); - for (int i=0; iselectedAll()) + { + matches.append(view.index().value()); + } + else if (not this->isEmpty()) { - this_idxs.append(typename T::Index(i)); + int match = this->idxs.indexOf(view.index()); + + if (match != -1) + matches.append(match); } } - if (other_idxs.isEmpty()) + return matches; + } + + /** Return the index in this collection of any views that + * matches 'views'. This returns an empty list if none of + * the views are in this collection + */ + template + SIRE_OUTOFLINE_TEMPLATE + QList + Selector::find(const Selector &views) const + { + QList matches; + + if (MoleculeView::isSameMolecule(views)) { - other_idxs.reserve(n); - for (int i=0; iselectedAll()) + { + if (views.selectedAll()) + { + for (int i = 0; i < this->count(); ++i) + { + matches.append(i); + } + } + else if (not views.isEmpty()) + { + for (const auto &idx : views.idxs) + { + matches.append(idx.value()); + } + } + } + else if (not this->isEmpty()) { - other_idxs.append(typename T::Index(i)); + if (views.selectedAll()) + { + for (int i = 0; i < this->count(); ++i) + { + matches.append(i); + } + } + else if (not views.isEmpty()) + { + for (const auto &idx : views.idxs) + { + int match = this->idxs.indexOf(idx); + + if (match != -1) + matches.append(match); + } + } } } - auto seen = _list_to_set(other_idxs); + return matches; + } - for (const auto &idx : this_idxs) + /** Return the set that has a completely inverted selection */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::invert() const + { + if (this->isEmpty()) { - if (seen.contains(idx)) - ret.idxs.append(idx); + throw SireMol::missing_atom(QObject::tr( + "Cannot invert an empty selection!"), + CODELOC); } - - if (ret.idxs.isEmpty()) + else if (this->selectedAll()) { return Selector(); } + else + { + Selector ret(*this); + ret.idxs.clear(); - return ret; - } -} + const int n = detail::getCount(this->data().info()); -/** Return the intersection of this set with 'view' + if (this->idxs.count() == 1) + { + auto seen = this->idxs.at(0); - \throw SireError::incompatible_error -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::intersection(const T &view) const -{ - return this->intersection(Selector(view)); -} + for (int i = 0; i < n; ++i) + { + typename T::Index idx(i); -/** Return the intersection of this set with the views identified - by the ID 'id' - - \throw SireMol::missing_atom - \throw SireMol::missing_residue - \throw SireMol::missing_chain - \throw SireMol::missing_segment - \throw SireMol::missing_cutgroup - \throw SireError::invalid_index -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::intersection(const typename T::ID &id) const -{ - return this->intersection(Selector(this->data(), id)); -} + if (idx != seen) + ret.idxs.append(idx); + } + } + else + { + auto seen = _list_to_set(this->idxs); -/** Return the set that has a completely inverted selection */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::invert() const -{ - if (this->isEmpty()) - { - throw SireMol::missing_atom(QObject::tr( - "Cannot invert an empty selection!"), CODELOC); - } - else if (this->selectedAll()) - { - return Selector(); + for (int i = 0; i < n; ++i) + { + typename T::Index idx(i); + + if (not seen.contains(idx)) + ret.idxs.append(idx); + } + } + + return ret; + } } - else - { - Selector ret(*this); - ret.idxs.clear(); - const int n = detail::getCount(this->data().info()); + /** Return whether this set contains all of the views + in 'other' */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::contains(const Selector &other) const + { + if (this->isEmpty() or other.isEmpty()) + return false; - if (this->idxs.count() == 1) - { - auto seen = this->idxs.at(0); + MoleculeView::assertSameMolecule(other); - for (int i=0; iselectedAll()) + return true; + else if (other.selectedAll()) + return false; - if (idx != seen) - ret.idxs.append(idx); - } - } else { auto seen = _list_to_set(this->idxs); - for (int i=0; i -SIRE_OUTOFLINE_TEMPLATE -bool Selector::contains(const Selector &other) const -{ - if (this->isEmpty() or other.isEmpty()) - return false; + /** Return whether this set contains some of the view + in other - MoleculeView::assertSameMolecule(other); + \throw SireError::incompatible_error + */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::intersects(const Selector &other) const + { + if (this->isEmpty() or other.isEmpty()) + return false; - if (this->selectedAll()) - return true; - else if (other.selectedAll()) - return false; + MoleculeView::assertSameMolecule(other); + + if (this->selectedAll() or other.selectedAll()) + return true; - else - { auto seen = _list_to_set(this->idxs); for (const auto &idx : other.idxs) { - if (not seen.contains(idx)) - return false; + if (seen.contains(idx)) + return true; } - return true; - } -} - -/** Return whether this set contains some of the view - in other - - \throw SireError::incompatible_error -*/ -template -SIRE_OUTOFLINE_TEMPLATE -bool Selector::intersects(const Selector &other) const -{ - if (this->isEmpty() or other.isEmpty()) return false; + } - MoleculeView::assertSameMolecule(other); - - if (this->selectedAll() or other.selectedAll()) - return true; + /** Return whether or not this set contains the view 'view' */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::contains(const T &view) const + { + return this->contains(Selector(view)); + } - auto seen = _list_to_set(this->idxs); + /** Return whether or not this set contains all of the + view identified by the ID 'id' */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::contains(const typename T::ID &id) const + { + return this->contains(Selector(this->data(), id)); + } - for (const auto &idx : other.idxs) + /** Return whether or not this set contains the view 'view' */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::intersects(const T &view) const { - if (seen.contains(idx)) - return true; + return this->intersects(Selector(view)); } - return false; -} + /** Return whether this set contains some of the views + identified by the ID 'id' */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::intersects(const typename T::ID &id) const + { + return this->intersects(Selector(this->data(), id)); + } -/** Return whether or not this set contains the view 'view' */ -template -SIRE_OUTOFLINE_TEMPLATE -bool Selector::contains(const T &view) const -{ - return this->contains(Selector(view)); -} + /** Return all of the atoms selected in this set */ + template + SIRE_OUTOFLINE_TEMPLATE + AtomSelection + Selector::selection() const + { + if (this->isEmpty()) + return AtomSelection(); -/** Return whether or not this set contains all of the - view identified by the ID 'id' */ -template -SIRE_OUTOFLINE_TEMPLATE -bool Selector::contains(const typename T::ID &id) const -{ - return this->contains(Selector(this->data(), id)); -} + else if (this->selectedAll()) + { + return AtomSelection(this->data()); + } -/** Return whether or not this set contains the view 'view' */ -template -SIRE_OUTOFLINE_TEMPLATE -bool Selector::intersects(const T &view) const -{ - return this->intersects(Selector(view)); -} + AtomSelection selected_atoms(this->data()); -/** Return whether this set contains some of the views - identified by the ID 'id' */ -template -SIRE_OUTOFLINE_TEMPLATE -bool Selector::intersects(const typename T::ID &id) const -{ - return this->intersects(Selector(this->data(), id)); -} + selected_atoms.selectNone(); -/** Return all of the atoms selected in this set */ -template -SIRE_OUTOFLINE_TEMPLATE -AtomSelection Selector::selection() const -{ - if (this->isEmpty()) - return AtomSelection(); + for (const auto &idx : this->idxs) + { + selected_atoms.select(idx); + } - else if (this->selectedAll()) - { - return AtomSelection(this->data()); + return selected_atoms; } - AtomSelection selected_atoms(this->data()); + /** Return the selection of the atoms in the ith view - selected_atoms.selectNone(); - - for (const auto &idx : this->idxs) + \throw SireError::invalid_index + */ + template + SIRE_OUTOFLINE_TEMPLATE + AtomSelection + Selector::selection(int i) const { - selected_atoms.select(idx); + return this->operator()(i).selection(); } - return selected_atoms; -} - -/** Return the selection of the atoms in the ith view - - \throw SireError::invalid_index -*/ -template -SIRE_OUTOFLINE_TEMPLATE -AtomSelection Selector::selection(int i) const -{ - return this->operator()(i).selection(); -} + /** Return the selection of the atoms in the ith to jth views -/** Return the selection of the atoms in the ith to jth views - - \throw SireError::invalid_index -*/ -template -SIRE_OUTOFLINE_TEMPLATE -AtomSelection Selector::selection(int i, int j) const -{ - return this->operator()(i, j).selection(); -} + \throw SireError::invalid_index + */ + template + SIRE_OUTOFLINE_TEMPLATE + AtomSelection + Selector::selection(int i, int j) const + { + return this->operator()(i, j).selection(); + } -/** Return an object that can move a copy of all of the views - in this set */ -template -SIRE_OUTOFLINE_TEMPLATE -Mover< Selector > Selector::move() const -{ - return Mover< Selector >(*this); -} + /** Return an object that can move a copy of all of the views + in this set */ + template + SIRE_OUTOFLINE_TEMPLATE + Mover> + Selector::move() const + { + return Mover>(*this); + } -/** Return an object that can move the ith view in this set */ -template -SIRE_OUTOFLINE_TEMPLATE -Mover< Selector > Selector::move(int i) const -{ - return Mover< Selector >(Selector(this->operator()(i))); -} + /** Return an object that can move the ith view in this set */ + template + SIRE_OUTOFLINE_TEMPLATE + Mover> + Selector::move(int i) const + { + return Mover>(Selector(this->operator()(i))); + } -/** Return an object that can move the ith to jth views in this set */ -template -SIRE_OUTOFLINE_TEMPLATE -Mover< Selector > Selector::move(int i, int j) const -{ - return Mover< Selector >(this->operator()(i,j)); -} + /** Return an object that can move the ith to jth views in this set */ + template + SIRE_OUTOFLINE_TEMPLATE + Mover> + Selector::move(int i, int j) const + { + return Mover>(this->operator()(i, j)); + } -/** Return an evaluator that can evaluate properties over all - of the views in this set */ -template -SIRE_OUTOFLINE_TEMPLATE -Evaluator Selector::evaluate() const -{ - return Evaluator(*this); -} + /** Return an evaluator that can evaluate properties over all + of the views in this set */ + template + SIRE_OUTOFLINE_TEMPLATE + Evaluator + Selector::evaluate() const + { + return Evaluator(*this); + } -/** Return an evaluator that can evaluate properties over the - ith view in this set */ -template -SIRE_OUTOFLINE_TEMPLATE -Evaluator Selector::evaluate(int i) const -{ - return Evaluator(this->operator()(i)); -} + /** Return an evaluator that can evaluate properties over the + ith view in this set */ + template + SIRE_OUTOFLINE_TEMPLATE + Evaluator + Selector::evaluate(int i) const + { + return Evaluator(this->operator()(i)); + } -/** Return an evaluator that can evaluate properties over - the ith to jth views in this set */ -template -SIRE_OUTOFLINE_TEMPLATE -Evaluator Selector::evaluate(int i, int j) const -{ - return Evaluator(this->operator()(i,j)); -} + /** Return an evaluator that can evaluate properties over + the ith to jth views in this set */ + template + SIRE_OUTOFLINE_TEMPLATE + Evaluator + Selector::evaluate(int i, int j) const + { + return Evaluator(this->operator()(i, j)); + } -/** Return a selector that can change the selection of this view */ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::selector() const -{ - return *this; -} + /** Return a selector that can change the selection of this view */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::selector() const + { + return *this; + } -/** Return a selector for the ith view that can change the - selection of that view + /** Return a selector for the ith view that can change the + selection of that view - \throw SireError::invalid_index -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::selector(int i) const -{ - return Selector(this->operator()(i)); -} + \throw SireError::invalid_index + */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::selector(int i) const + { + return Selector(this->operator()(i)); + } -/** Return a selector for the ith to jth views + /** Return a selector for the ith to jth views - \throw SireError::invalid_index -*/ -template -SIRE_OUTOFLINE_TEMPLATE -Selector Selector::selector(int i, int j) const -{ - return this->operator()(i, j); -} + \throw SireError::invalid_index + */ + template + SIRE_OUTOFLINE_TEMPLATE + Selector + Selector::selector(int i, int j) const + { + return this->operator()(i, j); + } -/** Return a list of the values of the property called 'key' for each - of the views in this set, in the order that they appear in this set. + /** Return a list of the values of the property called 'key' for each + of the views in this set, in the order that they appear in this set. - \throw SireBase::missing_property - \throw SireError::invalid_cast -*/ -template -template -SIRE_OUTOFLINE_TEMPLATE -QList Selector::property(const PropertyName &key) const -{ - T *ptr = 0; - return detail::get_property(ptr, this->data(), this->IDs(), key); -} + \throw SireBase::missing_property + \throw SireError::invalid_cast + */ + template + template + SIRE_OUTOFLINE_TEMPLATE + QList + Selector::property(const PropertyName &key) const + { + T *ptr = 0; + return detail::get_property(ptr, this->data(), this->IDs(), key); + } -/** Return a list of all of the metadata called 'metakey' for each - of the views in this set, in the order they appear in this set. + /** Return a list of all of the metadata called 'metakey' for each + of the views in this set, in the order they appear in this set. - \throw SireBase::missing_property - \throw SireError::invalid_cast -*/ -template -template -SIRE_OUTOFLINE_TEMPLATE -QList Selector::metadata(const PropertyName &metakey) const -{ - T *ptr = 0; - return detail::get_metadata(ptr, this->data(), - this->IDs(), metakey); -} + \throw SireBase::missing_property + \throw SireError::invalid_cast + */ + template + template + SIRE_OUTOFLINE_TEMPLATE + QList + Selector::metadata(const PropertyName &metakey) const + { + T *ptr = 0; + return detail::get_metadata(ptr, this->data(), + this->IDs(), metakey); + } -/** Return a list of all of the metadata called 'key'/'metakey' for each - of the views in this set, in the order they appear in this set. + /** Return a list of all of the metadata called 'key'/'metakey' for each + of the views in this set, in the order they appear in this set. - \throw SireBase::missing_property - \throw SireError::invalid_cast -*/ -template -template -SIRE_OUTOFLINE_TEMPLATE -QList Selector::metadata(const PropertyName &key, - const PropertyName &metakey) const -{ - T *ptr = 0; - return detail::get_metadata(ptr, this->data(), this->IDs(), - key, metakey); -} + \throw SireBase::missing_property + \throw SireError::invalid_cast + */ + template + template + SIRE_OUTOFLINE_TEMPLATE + QList + Selector::metadata(const PropertyName &key, + const PropertyName &metakey) const + { + T *ptr = 0; + return detail::get_metadata(ptr, this->data(), this->IDs(), + key, metakey); + } -/** Set the property at key 'key' for all of the views in this set - to the values in 'values', with the values given in the same - order as the views in this set. + /** Set the property at key 'key' for all of the views in this set + to the values in 'values', with the values given in the same + order as the views in this set. - \throw SireError::incompatible_error - \throw SireError::invalid_cast -*/ -template -template -SIRE_OUTOFLINE_TEMPLATE -void Selector::setProperty(const QString &key, const QList &values) -{ - T *ptr = 0; - detail::set_property(ptr, this->data(), this->IDs(), key, values); -} - -/** Set the metadata at key 'metakey' for all of the views in this set - to the values in 'values', with the values given in the same - order as the views in this set. + \throw SireError::incompatible_error + \throw SireError::invalid_cast + */ + template + template + SIRE_OUTOFLINE_TEMPLATE void Selector::setProperty(const QString &key, const QList &values) + { + T *ptr = 0; + detail::set_property(ptr, this->data(), this->IDs(), key, values); + } - \throw SireError::incompatible_error - \throw SireError::invalid_cast -*/ -template -template -SIRE_OUTOFLINE_TEMPLATE -void Selector::setMetadata(const QString &metakey, const QList &values) -{ - T *ptr = 0; - detail::set_metadata(ptr, this->data(), this->IDs(), metakey, values); -} + /** Set the metadata at key 'metakey' for all of the views in this set + to the values in 'values', with the values given in the same + order as the views in this set. + \throw SireError::incompatible_error + \throw SireError::invalid_cast + */ + template + template + SIRE_OUTOFLINE_TEMPLATE void Selector::setMetadata(const QString &metakey, const QList &values) + { + T *ptr = 0; + detail::set_metadata(ptr, this->data(), this->IDs(), metakey, values); + } -/** Set the metadata at key 'key'/'metakey' for all of the views in this set - to the values in 'values', with the values given in the same - order as the views in this set. + /** Set the metadata at key 'key'/'metakey' for all of the views in this set + to the values in 'values', with the values given in the same + order as the views in this set. - \throw SireError::incompatible_error - \throw SireError::invalid_cast -*/ -template -template -SIRE_OUTOFLINE_TEMPLATE -void Selector::setMetadata(const QString &key, const QString &metakey, - const QList &values) -{ - T *ptr = 0; - detail::set_metadata(ptr, this->data(), this->IDs(), key, metakey, values); -} + \throw SireError::incompatible_error + \throw SireError::invalid_cast + */ + template + template + SIRE_OUTOFLINE_TEMPLATE void Selector::setMetadata(const QString &key, const QString &metakey, + const QList &values) + { + T *ptr = 0; + detail::set_metadata(ptr, this->data(), this->IDs(), key, metakey, values); + } -/** Set the property at key 'key' for all of the views in this set - to the value 'value' + /** Set the property at key 'key' for all of the views in this set + to the value 'value' - \throw SireError::invalid_cast -*/ -template -template -SIRE_OUTOFLINE_TEMPLATE -void Selector::setProperty(const QString &key, const V &value) -{ - T *ptr = 0; - detail::set_property(ptr, this->data(), this->IDs(), key, value); -} + \throw SireError::invalid_cast + */ + template + template + SIRE_OUTOFLINE_TEMPLATE void Selector::setProperty(const QString &key, const V &value) + { + T *ptr = 0; + detail::set_property(ptr, this->data(), this->IDs(), key, value); + } -/** Set the metadata at metakey 'metakey' for all of the views in this set - to the value 'value' + /** Set the metadata at metakey 'metakey' for all of the views in this set + to the value 'value' - \throw SireError::invalid_cast -*/ -template -template -SIRE_OUTOFLINE_TEMPLATE -void Selector::setMetadata(const QString &metakey, V &value) -{ - T *ptr = 0; - detail::set_metadata(ptr, this->data(), this->IDs(), metakey, value); -} + \throw SireError::invalid_cast + */ + template + template + SIRE_OUTOFLINE_TEMPLATE void Selector::setMetadata(const QString &metakey, V &value) + { + T *ptr = 0; + detail::set_metadata(ptr, this->data(), this->IDs(), metakey, value); + } -/** Set the metadata at key 'key'/'metakey' for all of the views in this set - to the value 'value' + /** Set the metadata at key 'key'/'metakey' for all of the views in this set + to the value 'value' - \throw SireError::invalid_cast -*/ -template -template -SIRE_OUTOFLINE_TEMPLATE -void Selector::setMetadata(const QString &key, const QString &metakey, - const V &value) -{ - T *ptr = 0; - detail::set_metadata(ptr, this->data(), this->IDs(), key, metakey, value); -} + \throw SireError::invalid_cast + */ + template + template + SIRE_OUTOFLINE_TEMPLATE void Selector::setMetadata(const QString &key, const QString &metakey, + const V &value) + { + T *ptr = 0; + detail::set_metadata(ptr, this->data(), this->IDs(), key, metakey, value); + } -/** Return whether or not the views of this selector has a property - at key 'key' */ -template -SIRE_OUTOFLINE_TEMPLATE -bool Selector::hasProperty(const PropertyName &key) const -{ - T *ptr = 0; - return detail::has_property(ptr, this->data(), key); -} + /** Return whether or not the views of this selector has a property + at key 'key' */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::hasProperty(const PropertyName &key) const + { + T *ptr = 0; + return detail::has_property(ptr, this->data(), key); + } -/** Return whether or not the views of this selector have metadata - at metakey 'metakey' */ -template -SIRE_OUTOFLINE_TEMPLATE -bool Selector::hasMetadata(const PropertyName &metakey) const -{ - T *ptr = 0; - return detail::has_metadata(ptr, this->data(), metakey); -} + /** Return whether or not the views of this selector have metadata + at metakey 'metakey' */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::hasMetadata(const PropertyName &metakey) const + { + T *ptr = 0; + return detail::has_metadata(ptr, this->data(), metakey); + } -/** Return whether or not the property at key 'key' for the views - of this selector has metadata at metakey 'metakey' + /** Return whether or not the property at key 'key' for the views + of this selector has metadata at metakey 'metakey' - \throw SireBase::missing_property -*/ -template -SIRE_OUTOFLINE_TEMPLATE -bool Selector::hasMetadata(const PropertyName &key, - const PropertyName &metakey) const -{ - T *ptr = 0; - return detail::has_metadata(ptr, this->data(), key, metakey); -} + \throw SireBase::missing_property + */ + template + SIRE_OUTOFLINE_TEMPLATE bool Selector::hasMetadata(const PropertyName &key, + const PropertyName &metakey) const + { + T *ptr = 0; + return detail::has_metadata(ptr, this->data(), key, metakey); + } -/** Return all of the keys for the properties attached to the - parts of this selection */ -template -SIRE_OUTOFLINE_TEMPLATE -QStringList Selector::propertyKeys() const -{ - if (this->isEmpty()) - return QStringList(); - else - return this->operator()(0).propertyKeys(); -} + /** Return all of the keys for the properties attached to the + parts of this selection */ + template + SIRE_OUTOFLINE_TEMPLATE + QStringList + Selector::propertyKeys() const + { + if (this->isEmpty()) + return QStringList(); + else + return this->operator()(0).propertyKeys(); + } -/** Return all of the metakeys for the metadata attached to the - parts of this selection */ -template -SIRE_OUTOFLINE_TEMPLATE -QStringList Selector::metadataKeys() const -{ - if (this->isEmpty()) - return QStringList(); - else - return this->operator()(0).metadataKeys(); -} + /** Return all of the metakeys for the metadata attached to the + parts of this selection */ + template + SIRE_OUTOFLINE_TEMPLATE + QStringList + Selector::metadataKeys() const + { + if (this->isEmpty()) + return QStringList(); + else + return this->operator()(0).metadataKeys(); + } -/** Return all of the metakeys for the metadata attached to the - parts of this selection for the property at key 'key' + /** Return all of the metakeys for the metadata attached to the + parts of this selection for the property at key 'key' - \throw SireBase::missing_property -*/ -template -SIRE_OUTOFLINE_TEMPLATE -QStringList Selector::metadataKeys(const PropertyName &key) const -{ - if (this->isEmpty()) - return QStringList(); - else - return this->operator()(0).metadataKeys(key); -} + \throw SireBase::missing_property + */ + template + SIRE_OUTOFLINE_TEMPLATE + QStringList + Selector::metadataKeys(const PropertyName &key) const + { + if (this->isEmpty()) + return QStringList(); + else + return this->operator()(0).metadataKeys(key); + } -#endif //SIRE_SKIP_INLINE_FUNCTIONS +#endif // SIRE_SKIP_INLINE_FUNCTIONS } // end of namespace SireMol #ifndef SIRE_SKIP_INLINE_FUNCTIONS /** Extract from a binary datastream */ -template +template SIRE_OUTOFLINE_TEMPLATE -SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SireMol::Selector &views) + SIREMOL_EXPORT QDataStream & + operator>>(QDataStream &ds, SireMol::Selector &views) { QString cls; SireStream::VersionID version; @@ -1862,8 +2004,10 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SireMol::Selector &vi if (cls != QString(SireMol::Selector::typeName())) { throw SireStream::corrupted_data(QObject::tr( - "Found the wrong class (%1) when trying to read a %2.") - .arg(cls).arg(SireMol::Selector::typeName()), CODELOC); + "Found the wrong class (%1) when trying to read a %2.") + .arg(cls) + .arg(SireMol::Selector::typeName()), + CODELOC); } ds >> version; @@ -1871,7 +2015,7 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SireMol::Selector &vi if (version == 2) { SireStream::SharedDataStream sds(ds); - sds >> views.idxs >> static_cast(views); + sds >> views.idxs >> static_cast(views); } else if (version == 1) { @@ -1894,15 +2038,16 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SireMol::Selector &vi } /** Serialise to a binary datastream */ -template +template SIRE_OUTOFLINE_TEMPLATE -SIREMOL_EXPORT QDataStream &operator<<(QDataStream &ds, const SireMol::Selector &views) + SIREMOL_EXPORT QDataStream & + operator<<(QDataStream &ds, const SireMol::Selector &views) { ds << QString(SireMol::Selector::typeName()) << SireStream::VersionID(2); SireStream::SharedDataStream sds(ds); - sds << views.idxs << static_cast(views); + sds << views.idxs << static_cast(views); return ds; } diff --git a/corelib/src/libs/SireMol/selectorm.hpp b/corelib/src/libs/SireMol/selectorm.hpp index fc88ca39b..82c137c18 100644 --- a/corelib/src/libs/SireMol/selectorm.hpp +++ b/corelib/src/libs/SireMol/selectorm.hpp @@ -41,2450 +41,2630 @@ SIRE_BEGIN_HEADER namespace SireMol { -template -class SelectorM; + template + class SelectorM; -class SelectorMol; + class SelectorMol; } -template -SIREMOL_EXPORT QDataStream& operator<<(QDataStream&, const SireMol::SelectorM&); +template +SIREMOL_EXPORT QDataStream &operator<<(QDataStream &, const SireMol::SelectorM &); -template -SIREMOL_EXPORT QDataStream& operator>>(QDataStream&, SireMol::SelectorM&); +template +SIREMOL_EXPORT QDataStream &operator>>(QDataStream &, SireMol::SelectorM &); namespace SireMol { -/** This is an analogue of the Selector class that is designed - to hold views from multiple molecules -*/ -template -class SIREMOL_EXPORT SelectorM - : public SireBase::ConcreteProperty,SireBase::Property> -{ + /** This is an analogue of the Selector class that is designed + to hold views from multiple molecules + */ + template + class SIREMOL_EXPORT SelectorM + : public SireBase::ConcreteProperty, SireBase::Property> + { -friend SIREMOL_EXPORT QDataStream& ::operator<<<>(QDataStream&, const SelectorM&); -friend SIREMOL_EXPORT QDataStream& ::operator>><>(QDataStream&, SelectorM&); + friend SIREMOL_EXPORT QDataStream & ::operator<< <>(QDataStream &, const SelectorM &); + friend SIREMOL_EXPORT QDataStream & ::operator>><>(QDataStream &, SelectorM &); -public: - typedef typename QList< Selector >::const_iterator iterator; - typedef typename QList< Selector >::const_iterator const_iterator; + public: + typedef typename QList>::const_iterator iterator; + typedef typename QList>::const_iterator const_iterator; - SelectorM(); - SelectorM(const T &view); - SelectorM(const Selector &views); - SelectorM(const Molecules &mols); - SelectorM(const MoleculeGroup &mols); - SelectorM(const MolGroupsBase &mols); - SelectorM(const SelectResult &mols); + SelectorM(); + SelectorM(const T &view); + SelectorM(const Selector &views); + SelectorM(const Molecules &mols); + SelectorM(const MoleculeGroup &mols); + SelectorM(const MolGroupsBase &mols); + SelectorM(const SelectResult &mols); - SelectorM(const SelectorMol &mols); - SelectorM(const SelectorMol &mols, const SireBase::Slice &slice); - SelectorM(const SelectorMol &mols, const QList &idxs); - SelectorM(const SelectorMol &mols, const QString &name, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); - SelectorM(const SelectorMol &mols, const typename T::ID &id); + SelectorM(const SelectorMol &mols); + SelectorM(const SelectorMol &mols, const SireBase::Slice &slice); + SelectorM(const SelectorMol &mols, const QList &idxs); + SelectorM(const SelectorMol &mols, const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); + SelectorM(const SelectorMol &mols, const typename T::ID &id); - template - SelectorM(const SelectorM &other); - template - SelectorM(const SelectorM &other, const SireBase::Slice &slice); - template - SelectorM(const SelectorM &other, const QList &idxs); - template - SelectorM(const SelectorM &other, const QString &name); - template - SelectorM(const SelectorM &other, const typename T::ID &id); + template + SelectorM(const SelectorM &other); + template + SelectorM(const SelectorM &other, const SireBase::Slice &slice); + template + SelectorM(const SelectorM &other, const QList &idxs); + template + SelectorM(const SelectorM &other, const QString &name); + template + SelectorM(const SelectorM &other, const typename T::ID &id); - SelectorM(const SelectorM &other); + SelectorM(const SelectorM &other); - virtual ~SelectorM(); + virtual ~SelectorM(); - static const char* typeName(); + static const char *typeName(); - virtual SelectorM* clone() const - { - return new SelectorM(*this); - } + virtual SelectorM *clone() const + { + return new SelectorM(*this); + } - SelectorM& operator=(const SelectorM &other); + SelectorM &operator=(const SelectorM &other); - bool operator==(const SelectorM &other) const; - bool operator!=(const SelectorM &other) const; + bool operator==(const SelectorM &other) const; + bool operator!=(const SelectorM &other) const; - T operator[](int i) const; - SelectorM operator[](const SireBase::Slice &slice) const; - SelectorM operator[](const QList &idxs) const; - T operator[](const QString &name) const; - T operator[](const typename T::ID &id) const; + T operator[](int i) const; + SelectorM operator[](const SireBase::Slice &slice) const; + SelectorM operator[](const QList &idxs) const; + T operator[](const QString &name) const; + T operator[](const typename T::ID &id) const; - T operator()(int i) const; - T operator()(const QString &name) const; - T operator()(const typename T::ID &id) const; + T operator()(int i) const; + T operator()(const QString &name) const; + T operator()(const typename T::ID &id) const; - QList toList() const; - Molecules toMolecules() const; + QList toList() const; + Molecules toMolecules() const; - int count() const; - int size() const; + int count() const; + int size() const; - void update(const Molecules &molecules); + void update(const Molecules &molecules); - EvaluatorM evaluate() const; + EvaluatorM evaluate() const; - MoleculeGroup toMoleculeGroup() const; - SelectResult toSelectResult() const; + MoleculeGroup toMoleculeGroup() const; + SelectResult toSelectResult() const; - bool isSelector() const; + bool isSelector() const; - SelectorM add(const SelectorM &other) const; - SelectorM add(const Selector &views) const; - SelectorM add(const T &view) const; + QList find(const T &view) const; + QList find(const Selector &views) const; + QList find(const SelectorM &views) const; - SelectorM subtract(const SelectorM &other) const; - SelectorM subtract(const Selector &views) const; - SelectorM subtract(const T &view) const; + SelectorM add(const SelectorM &other) const; + SelectorM add(const Selector &views) const; + SelectorM add(const T &view) const; - SelectorM intersection(const SelectorM &other) const; - SelectorM intersection(const Selector &views) const; - SelectorM intersection(const T &view) const; + SelectorM subtract(const SelectorM &other) const; + SelectorM subtract(const Selector &views) const; + SelectorM subtract(const T &view) const; - SelectorM invert() const; + SelectorM intersection(const SelectorM &other) const; + SelectorM intersection(const Selector &views) const; + SelectorM intersection(const T &view) const; - bool intersects(const SelectorM &other) const; - bool intersects(const Selector &view) const; - bool intersects(const T &view) const; + SelectorM invert() const; - bool contains(const SelectorM &other) const; - bool contains(const Selector &view) const; - bool contains(const T &view) const; + bool intersects(const SelectorM &other) const; + bool intersects(const Selector &view) const; + bool intersects(const T &view) const; - Molecule molecule(int i, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - Molecule molecule(const QString &name, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - Molecule molecule(const MolID &molid, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); + bool contains(const SelectorM &other) const; + bool contains(const Selector &view) const; + bool contains(const T &view) const; - SelectorMol molecules() const; - SelectorMol molecules(int i, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - SelectorMol molecules(const SireBase::Slice &slice, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - SelectorMol molecules(const QList &idxs, + Molecule molecule(int i, const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - SelectorMol molecules(const QString &name, + Molecule molecule(const QString &name, const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - SelectorMol molecules(const MolID &molid, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - - Atom atom(int i, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - Atom atom(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - Atom atom(const AtomID &atomid, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - - Residue residue(int i, + Molecule molecule(const MolID &molid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); + + SelectorMol molecules() const; + SelectorMol molecules(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorMol molecules(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorMol molecules(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorMol molecules(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorMol molecules(const MolID &molid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + Atom atom(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Atom atom(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Atom atom(const AtomID &atomid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + Residue residue(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Residue residue(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Residue residue(const ResID &resid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + Chain chain(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Chain chain(const QString &name, const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - Residue residue(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - Residue residue(const ResID &resid, + Chain chain(const ChainID &chainid, const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - Chain chain(int i, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - Chain chain(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - Chain chain(const ChainID &chainid, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Segment segment(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Segment segment(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Segment segment(const SegID &segid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - Segment segment(int i, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - Segment segment(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - Segment segment(const SegID &segid, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + CutGroup cutGroup(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + CutGroup cutGroup(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + CutGroup cutGroup(const CGID &cgid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - CutGroup cutGroup(int i, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - CutGroup cutGroup(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - CutGroup cutGroup(const CGID &cgid, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - - SelectorM atoms() const; - SelectorM atoms(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM atoms(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM atoms(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM atoms(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM atoms(const AtomID &atomid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SelectorM residues() const; - SelectorM residues(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM residues(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM residues(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM residues(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM residues(const ResID &resid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SelectorM chains() const; - SelectorM chains(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM chains(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM chains(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM chains(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM chains(const ChainID &chainid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SelectorM segments() const; - SelectorM segments(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM segments(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM segments(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM segments(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM segments(const SegID &segid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SelectorM cutGroups() const; - SelectorM cutGroups(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM cutGroups(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM cutGroups(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM cutGroups(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM cutGroups(const CGID &cgid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SelectResult search(const QString &search_string) const; - SelectResult search(const QString &search_string, - const SireBase::PropertyMap &map) const; - - QList IDs() const; - QList indexes() const; - QList numbers() const; - QList names() const; - - int nAtoms() const; - int nResidues() const; - int nChains() const; - int nSegments() const; - int nCutGroups() const; - int nMolecules() const; - - bool isEmpty() const; - - int nFrames() const; - int nFrames(const SireBase::PropertyMap &map) const; - - void loadFrame(int frame); - void saveFrame(int frame); - void saveFrame(); - void deleteFrame(int frame); - - void loadFrame(int frame, const SireBase::PropertyMap &map); - void saveFrame(int frame, const SireBase::PropertyMap &map); - void saveFrame(const SireBase::PropertyMap &map); - void deleteFrame(int frame, const SireBase::PropertyMap &map); - - const_iterator begin() const; - const_iterator end() const; - - const_iterator constBegin() const; - const_iterator constEnd() const; - - virtual QString toString() const; - -protected: - void _append(const T &view); - - /** The actual views */ - QList< Selector > vws; -}; + SelectorM atoms() const; + SelectorM atoms(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM atoms(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM atoms(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM atoms(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM atoms(const AtomID &atomid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SelectorM residues() const; + SelectorM residues(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM residues(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM residues(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM residues(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM residues(const ResID &resid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SelectorM chains() const; + SelectorM chains(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM chains(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM chains(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM chains(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM chains(const ChainID &chainid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SelectorM segments() const; + SelectorM segments(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM segments(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM segments(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM segments(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM segments(const SegID &segid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SelectorM cutGroups() const; + SelectorM cutGroups(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM cutGroups(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM cutGroups(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM cutGroups(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM cutGroups(const CGID &cgid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SelectResult search(const QString &search_string) const; + SelectResult search(const QString &search_string, + const SireBase::PropertyMap &map) const; + + QList IDs() const; + QList indexes() const; + QList numbers() const; + QList names() const; + + int nAtoms() const; + int nResidues() const; + int nChains() const; + int nSegments() const; + int nCutGroups() const; + int nMolecules() const; + + bool isEmpty() const; + + int nFrames() const; + int nFrames(const SireBase::PropertyMap &map) const; + + void loadFrame(int frame); + void saveFrame(int frame); + void saveFrame(); + void deleteFrame(int frame); + + void loadFrame(int frame, const SireBase::PropertyMap &map); + void saveFrame(int frame, const SireBase::PropertyMap &map); + void saveFrame(const SireBase::PropertyMap &map); + void deleteFrame(int frame, const SireBase::PropertyMap &map); + + const_iterator begin() const; + const_iterator end() const; + + const_iterator constBegin() const; + const_iterator constEnd() const; + + virtual QString toString() const; + + protected: + void _append(const T &view); + + /** The actual views */ + QList> vws; + }; #ifndef SIRE_SKIP_INLINE_FUNCTIONS #ifndef GCCXML_PARSE -namespace detail -{ - -template -SIRE_OUTOFLINE_TEMPLATE -bool _usesParallel(const QList vws, const SireBase::PropertyMap &map) -{ - if (vws.count() < 16) - return false; - - else if (map["parallel"].hasValue()) + namespace detail { - return map["parallel"].value().asA().value(); - } - - return true; -} - -template -SIRE_OUTOFLINE_TEMPLATE -int _nFrames(const QList &vws, const SireBase::PropertyMap &map) -{ - int nframes = std::numeric_limits::max(); - if (_usesParallel(vws, map)) - { - nframes = tbb::parallel_reduce( tbb::blocked_range(0, vws.count()), - std::numeric_limits::max(), - [&](tbb::blocked_range r, int my_nframes) + template + SIRE_OUTOFLINE_TEMPLATE bool _usesParallel(const QList vws, const SireBase::PropertyMap &map) { - for (int i=r.begin(); i().value(); } - return my_nframes; + return true; + } - }, [](int a, int b){ return std::min(a, b);}); - } - else - { - for (const auto &view : vws) + template + SIRE_OUTOFLINE_TEMPLATE int _nFrames(const QList &vws, const SireBase::PropertyMap &map) { - nframes = std::min(nframes, view.nFrames(map)); + int nframes = std::numeric_limits::max(); - if (nframes == 0) - break; - } - } + if (_usesParallel(vws, map)) + { + nframes = tbb::parallel_reduce( + tbb::blocked_range(0, vws.count()), + std::numeric_limits::max(), + [&](tbb::blocked_range r, int my_nframes) + { + for (int i = r.begin(); i < r.end(); ++i) + { + my_nframes = std::min(my_nframes, vws.at(i).nFrames(map)); + } + + return my_nframes; + }, + [](int a, int b) + { return std::min(a, b); }); + } + else + { + for (const auto &view : vws) + { + nframes = std::min(nframes, view.nFrames(map)); - return nframes; -} + if (nframes == 0) + break; + } + } -template -SIRE_OUTOFLINE_TEMPLATE -void _loadFrame(QList &vws, int frame, const SireBase::PropertyMap &map) -{ - const int nframes = _nFrames(vws, map); + return nframes; + } - if (not (nframes == 0 and frame == 0)) - frame = SireID::Index(frame).map(nframes); + template + SIRE_OUTOFLINE_TEMPLATE void _loadFrame(QList &vws, int frame, const SireBase::PropertyMap &map) + { + const int nframes = _nFrames(vws, map); - vws.detach(); - const int n = vws.count(); + if (not(nframes == 0 and frame == 0)) + frame = SireID::Index(frame).map(nframes); - if (_usesParallel(vws, map)) - { - tbb::parallel_for(tbb::blocked_range(0, n), - [&](tbb::blocked_range r) - { - for (int i=r.begin(); i(0, n), + [&](tbb::blocked_range r) + { + for (int i = r.begin(); i < r.end(); ++i) + { + vws[i].loadFrame(frame, map); + } + }); + } + else + { + for (int i = 0; i < n; ++i) + { + vws[i].loadFrame(frame, map); + } } - }); - } - else - { - for (int i=0; i -SIRE_OUTOFLINE_TEMPLATE -void _saveFrame(QList &vws, int frame, const SireBase::PropertyMap &map) -{ - frame = SireID::Index(frame).map(_nFrames(vws, map)); + template + SIRE_OUTOFLINE_TEMPLATE void _saveFrame(QList &vws, int frame, const SireBase::PropertyMap &map) + { + frame = SireID::Index(frame).map(_nFrames(vws, map)); - vws.detach(); - const int n = vws.count(); + vws.detach(); + const int n = vws.count(); - if (_usesParallel(vws, map)) - { - tbb::parallel_for(tbb::blocked_range(0, n), - [&](tbb::blocked_range r) - { - for (int i=r.begin(); i(0, n), + [&](tbb::blocked_range r) + { + for (int i = r.begin(); i < r.end(); ++i) + { + vws[i].saveFrame(frame, map); + } + }); + } + else + { + for (int i = 0; i < n; ++i) + { + vws[i].saveFrame(frame, map); + } } - }); - } - else - { - for (int i=0; i -SIRE_OUTOFLINE_TEMPLATE -void _saveFrame(QList &vws, const SireBase::PropertyMap &map) -{ - vws.detach(); - const int n = vws.count(); - if (_usesParallel(vws, map)) - { - tbb::parallel_for(tbb::blocked_range(0, n), - [&](tbb::blocked_range r) + template + SIRE_OUTOFLINE_TEMPLATE void _saveFrame(QList &vws, const SireBase::PropertyMap &map) { - for (int i=r.begin(); i(0, n), + [&](tbb::blocked_range r) + { + for (int i = r.begin(); i < r.end(); ++i) + { + vws[i].saveFrame(map); + } + }); + } + else + { + for (int i = 0; i < n; ++i) + { + vws[i].saveFrame(map); + } } - }); - } - else - { - for (int i=0; i -SIRE_OUTOFLINE_TEMPLATE -void _deleteFrame(QList &vws, int frame, const SireBase::PropertyMap &map) -{ - frame = SireID::Index(frame).map(_nFrames(vws, map)); + template + SIRE_OUTOFLINE_TEMPLATE void _deleteFrame(QList &vws, int frame, const SireBase::PropertyMap &map) + { + frame = SireID::Index(frame).map(_nFrames(vws, map)); - vws.detach(); - const int n = vws.count(); + vws.detach(); + const int n = vws.count(); - if (_usesParallel(vws, map)) - { - tbb::parallel_for(tbb::blocked_range(0, n), - [&](tbb::blocked_range r) - { - for (int i=r.begin(); i(0, n), + [&](tbb::blocked_range r) + { + for (int i = r.begin(); i < r.end(); ++i) + { + vws[i].deleteFrame(frame, map); + } + }); + } + else + { + for (int i = 0; i < n; ++i) + { + vws[i].deleteFrame(frame, map); + } } - }); - } - else - { - for (int i=0; i -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM() - : SireBase::ConcreteProperty,SireBase::Property>() -{} - -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const T &view) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - this->vws.append(Selector(view)); -} - -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const Selector &views) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - if (not views.isEmpty()) - this->vws.append(views); -} - -template -struct _get_view -{ - template - static int count(const C &mols) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM() + : SireBase::ConcreteProperty, SireBase::Property>() { - return mols.nAtoms(); } - template - static T at(const C &mols, int idx) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const T &view) + : SireBase::ConcreteProperty, SireBase::Property>() { - return mols.atom(idx); + this->vws.append(Selector(view)); } - template - static Selector get(const C &view) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const Selector &views) + : SireBase::ConcreteProperty, SireBase::Property>() { - if (view.template isA< Selector >()) - return view.template asA< Selector >(); - else - return view.atoms(); + if (not views.isEmpty()) + this->vws.append(views); } - static SelectorM getName(const SelectorM &view, const QString &name) + template + struct _get_view { - return view.atoms(name); - } + template + static int count(const C &mols) + { + return mols.nAtoms(); + } - static SelectorM getID(const SelectorM &view, - const typename T::ID &id) - { - return view.atoms(id); - } + template + static T at(const C &mols, int idx) + { + return mols.atom(idx); + } - template - static Selector get(const C &view, const ID &id) - { - return view.atoms(id); - } + template + static Selector get(const C &view) + { + if (view.template isA>()) + return view.template asA>(); + else + return view.atoms(); + } - static void raise_duplicate(const QString &id, int n) - { - throw SireMol::duplicate_atom(QObject::tr( - "Multiple atoms matched %1. Number of matches is %2.") - .arg(id).arg(n), CODELOC); - } + static SelectorM getName(const SelectorM &view, const QString &name) + { + return view.atoms(name); + } - static void raise_missing(const QString &id) - { - throw SireMol::missing_atom(QObject::tr( - "No atom matches %1.").arg(id), CODELOC); - } -}; + static SelectorM getID(const SelectorM &view, + const typename T::ID &id) + { + return view.atoms(id); + } -template<> -struct _get_view -{ - template - static int count(const C &mols) - { - return mols.nResidues(); - } + template + static Selector get(const C &view, const ID &id) + { + return view.atoms(id); + } - template - static Residue at(const C &mols, int idx) - { - return mols.residue(idx); - } + static void raise_duplicate(const QString &id, int n) + { + throw SireMol::duplicate_atom(QObject::tr( + "Multiple atoms matched %1. Number of matches is %2.") + .arg(id) + .arg(n), + CODELOC); + } - static SelectorM getName(const SelectorM &view, - const QString &name) - { - return view.residues(name); - } + static void raise_missing(const QString &id) + { + throw SireMol::missing_atom(QObject::tr( + "No atom matches %1.") + .arg(id), + CODELOC); + } + }; - static SelectorM getID(const SelectorM &view, - const Residue::ID &id) + template <> + struct _get_view { - return view.residues(id); - } + template + static int count(const C &mols) + { + return mols.nResidues(); + } - template - static Selector get(const C &view) - { - if (view.template isA< Selector >()) - return view.template asA< Selector >(); - else - return view.residues(); - } + template + static Residue at(const C &mols, int idx) + { + return mols.residue(idx); + } - template - static Selector get(const C &view, const ID &id) - { - return view.residues(id); - } + static SelectorM getName(const SelectorM &view, + const QString &name) + { + return view.residues(name); + } - static void raise_duplicate(const QString &id, int n) - { - throw SireMol::duplicate_residue(QObject::tr( - "Multiple residues matched %1. Number of matches is %2.") - .arg(id).arg(n), CODELOC); - } + static SelectorM getID(const SelectorM &view, + const Residue::ID &id) + { + return view.residues(id); + } - static void raise_missing(const QString &id) - { - throw SireMol::missing_residue(QObject::tr( - "No residue matches %1.").arg(id), CODELOC); - } -}; + template + static Selector get(const C &view) + { + if (view.template isA>()) + return view.template asA>(); + else + return view.residues(); + } -template<> -struct _get_view -{ - template - static int count(const C &mols) - { - return mols.nChains(); - } + template + static Selector get(const C &view, const ID &id) + { + return view.residues(id); + } - template - static Chain at(const C &mols, int idx) - { - return mols.chain(idx); - } + static void raise_duplicate(const QString &id, int n) + { + throw SireMol::duplicate_residue(QObject::tr( + "Multiple residues matched %1. Number of matches is %2.") + .arg(id) + .arg(n), + CODELOC); + } - static SelectorM getName(const SelectorM &view, - const QString &name) - { - return view.chains(name); - } + static void raise_missing(const QString &id) + { + throw SireMol::missing_residue(QObject::tr( + "No residue matches %1.") + .arg(id), + CODELOC); + } + }; - static SelectorM getID(const SelectorM &view, - const Chain::ID &id) + template <> + struct _get_view { - return view.chains(id); - } + template + static int count(const C &mols) + { + return mols.nChains(); + } - template - static Selector get(const C &view) - { - if (view.template isA< Selector >()) - return view.template asA< Selector >(); - else - return view.chains(); - } + template + static Chain at(const C &mols, int idx) + { + return mols.chain(idx); + } - template - static Selector get(const C &view, const ID &id) - { - return view.chains(id); - } + static SelectorM getName(const SelectorM &view, + const QString &name) + { + return view.chains(name); + } - static void raise_duplicate(const QString &id, int n) - { - throw SireMol::duplicate_chain(QObject::tr( - "Multiple chains matched %1. Number of matches is %2.") - .arg(id).arg(n), CODELOC); - } + static SelectorM getID(const SelectorM &view, + const Chain::ID &id) + { + return view.chains(id); + } - static void raise_missing(const QString &id) - { - throw SireMol::missing_chain(QObject::tr( - "No chain matches %1.").arg(id), CODELOC); - } -}; + template + static Selector get(const C &view) + { + if (view.template isA>()) + return view.template asA>(); + else + return view.chains(); + } -template<> -struct _get_view -{ - template - static int count(const C &mols) - { - return mols.nCutGroups(); - } + template + static Selector get(const C &view, const ID &id) + { + return view.chains(id); + } - template - static CutGroup at(const C &mols, int idx) - { - return mols.cutGroup(idx); - } + static void raise_duplicate(const QString &id, int n) + { + throw SireMol::duplicate_chain(QObject::tr( + "Multiple chains matched %1. Number of matches is %2.") + .arg(id) + .arg(n), + CODELOC); + } - static SelectorM getName(const SelectorM &view, - const QString &name) - { - return view.cutGroup(name); - } + static void raise_missing(const QString &id) + { + throw SireMol::missing_chain(QObject::tr( + "No chain matches %1.") + .arg(id), + CODELOC); + } + }; - static SelectorM getID(const SelectorM &view, - const CutGroup::ID &id) + template <> + struct _get_view { - return view.cutGroups(id); - } + template + static int count(const C &mols) + { + return mols.nCutGroups(); + } - template - static Selector get(const C &view) - { - if (view.template isA< Selector >()) - return view.template asA< Selector >(); - else - return view.cutGroups(); - } + template + static CutGroup at(const C &mols, int idx) + { + return mols.cutGroup(idx); + } - template - static Selector get(const C &view, const ID &id) - { - return view.cutGroups(id); - } + static SelectorM getName(const SelectorM &view, + const QString &name) + { + return view.cutGroup(name); + } - static void raise_duplicate(const QString &id, int n) - { - throw SireMol::duplicate_cutgroup(QObject::tr( - "Multiple CutGroups matched %1. Number of matches is %2.") - .arg(id).arg(n), CODELOC); - } + static SelectorM getID(const SelectorM &view, + const CutGroup::ID &id) + { + return view.cutGroups(id); + } - static void raise_missing(const QString &id) - { - throw SireMol::missing_cutgroup(QObject::tr( - "No CutGroup matches %1.").arg(id), CODELOC); - } -}; + template + static Selector get(const C &view) + { + if (view.template isA>()) + return view.template asA>(); + else + return view.cutGroups(); + } -template<> -struct _get_view -{ - template - static int count(const C &mols) - { - return mols.nSegments(); - } + template + static Selector get(const C &view, const ID &id) + { + return view.cutGroups(id); + } - template - static Segment at(const C &mols, int idx) - { - return mols.segment(idx); - } + static void raise_duplicate(const QString &id, int n) + { + throw SireMol::duplicate_cutgroup(QObject::tr( + "Multiple CutGroups matched %1. Number of matches is %2.") + .arg(id) + .arg(n), + CODELOC); + } - static SelectorM getName(const SelectorM &view, - const QString &name) - { - return view.segments(name); - } + static void raise_missing(const QString &id) + { + throw SireMol::missing_cutgroup(QObject::tr( + "No CutGroup matches %1.") + .arg(id), + CODELOC); + } + }; - static SelectorM getID(const SelectorM &view, - const Segment::ID &id) + template <> + struct _get_view { - return view.segments(id); - } + template + static int count(const C &mols) + { + return mols.nSegments(); + } - template - static Selector get(const C &view) - { - if (view.template isA< Selector >()) - return view.template asA< Selector >(); - else - return view.segments(); - } + template + static Segment at(const C &mols, int idx) + { + return mols.segment(idx); + } - template - static Selector get(const C &view, const ID &id) - { - return view.segments(id); - } + static SelectorM getName(const SelectorM &view, + const QString &name) + { + return view.segments(name); + } - static void raise_duplicate(const QString &id, int n) - { - throw SireMol::duplicate_segment(QObject::tr( - "Multiple segments matched %1. Number of matches is %2.") - .arg(id).arg(n), CODELOC); - } + static SelectorM getID(const SelectorM &view, + const Segment::ID &id) + { + return view.segments(id); + } - static void raise_missing(const QString &id) - { - throw SireMol::missing_segment(QObject::tr( - "No segment matches %1.").arg(id), CODELOC); - } -}; + template + static Selector get(const C &view) + { + if (view.template isA>()) + return view.template asA>(); + else + return view.segments(); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const SelectorMol &mols) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - for (const auto &mol : mols) - { - this->vws += _get_view::get(mol); - } -} + template + static Selector get(const C &view, const ID &id) + { + return view.segments(id); + } -template -SIRE_OUTOFLINE_TEMPLATE -void SelectorM::_append(const T &view) -{ - if (this->vws.isEmpty()) - { - this->vws.append(Selector(view)); - } - else if (this->vws.last().data().number() != view.data().number()) + static void raise_duplicate(const QString &id, int n) + { + throw SireMol::duplicate_segment(QObject::tr( + "Multiple segments matched %1. Number of matches is %2.") + .arg(id) + .arg(n), + CODELOC); + } + + static void raise_missing(const QString &id) + { + throw SireMol::missing_segment(QObject::tr( + "No segment matches %1.") + .arg(id), + CODELOC); + } + }; + + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const SelectorMol &mols) + : SireBase::ConcreteProperty, SireBase::Property>() { - // new molecule - this->vws.append(Selector(view)); + for (const auto &mol : mols) + { + this->vws += _get_view::get(mol); + } } - else + + template + SIRE_OUTOFLINE_TEMPLATE void SelectorM::_append(const T &view) { - // a new view in the current molecule - this->vws.last() = this->vws.last().add(view); + if (this->vws.isEmpty()) + { + this->vws.append(Selector(view)); + } + else if (this->vws.last().data().number() != view.data().number()) + { + // new molecule + this->vws.append(Selector(view)); + } + else + { + // a new view in the current molecule + this->vws.last() = this->vws.last().add(view); + } } -} -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const Molecules &molecules) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - if (not molecules.isEmpty()) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const Molecules &molecules) + : SireBase::ConcreteProperty, SireBase::Property>() { - auto toList = [](const QSet &molnums) + if (not molecules.isEmpty()) { - //return QList(molnums.constBegin(), molnums.constEnd()); - return molnums.values(); - }; + auto toList = [](const QSet &molnums) + { + // return QList(molnums.constBegin(), molnums.constEnd()); + return molnums.values(); + }; - auto molnums = toList(molecules.molNums()); + auto molnums = toList(molecules.molNums()); - //sort them, as this is also likely the order the molecules - //were read in from a file, and so more likely to be the - //order the user would expect - std::sort(molnums.begin(), molnums.end()); + // sort them, as this is also likely the order the molecules + // were read in from a file, and so more likely to be the + // order the user would expect + std::sort(molnums.begin(), molnums.end()); - this->vws.reserve(molnums.count()); + this->vws.reserve(molnums.count()); - for (const auto &molnum : molnums) - { - this->vws.append(_get_view::get(molecules.at(molnum))); + for (const auto &molnum : molnums) + { + this->vws.append(_get_view::get(molecules.at(molnum))); + } } } -} -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const MoleculeGroup &molecules) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - if (not molecules.isEmpty()) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const MoleculeGroup &molecules) + : SireBase::ConcreteProperty, SireBase::Property>() { - const auto molnums = molecules.molNums(); - this->vws.reserve(molnums.count()); - - for (const auto &molnum : molnums) + if (not molecules.isEmpty()) { - this->vws.append(_get_view::get(molecules.at(molnum))); + const auto molnums = molecules.molNums(); + this->vws.reserve(molnums.count()); + + for (const auto &molnum : molnums) + { + this->vws.append(_get_view::get(molecules.at(molnum))); + } } } -} -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const MolGroupsBase &molecules) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - if (not molecules.isEmpty()) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const MolGroupsBase &molecules) + : SireBase::ConcreteProperty, SireBase::Property>() { - const auto molnums = molecules.molNums(); - this->vws.reserve(molnums.count()); - - for (const auto &molnum : molnums) + if (not molecules.isEmpty()) { - this->vws.append(_get_view::get(molecules.at(molnum))); + const auto molnums = molecules.molNums(); + this->vws.reserve(molnums.count()); + + for (const auto &molnum : molnums) + { + this->vws.append(_get_view::get(molecules.at(molnum))); + } } } -} -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const SelectResult &molecules) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - if (not molecules.isEmpty()) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const SelectResult &molecules) + : SireBase::ConcreteProperty, SireBase::Property>() { - this->vws.reserve(molecules.count()); - - for (const auto &mol : molecules) + if (not molecules.isEmpty()) { - this->vws.append(_get_view::get(*mol)); - } - } -} + this->vws.reserve(molecules.count()); -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const SelectorMol &mols, const SireBase::Slice &slice) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - for (auto it = slice.begin(_get_view::count(mols)); - not it.atEnd(); it.next()) - { - this->_append(_get_view::at(mols, it.value())); + for (const auto &mol : molecules) + { + this->vws.append(_get_view::get(*mol)); + } + } } -} -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const SelectorMol &mols, const QList &idxs) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - for (const auto &idx : idxs) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const SelectorMol &mols, const SireBase::Slice &slice) + : SireBase::ConcreteProperty, SireBase::Property>() { - this->_append(_get_view::at(mols, idx)); + for (auto it = slice.begin(_get_view::count(mols)); + not it.atEnd(); it.next()) + { + this->_append(_get_view::at(mols, it.value())); + } } -} -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const SelectorMol &mols, const QString &name, - const SireBase::PropertyMap &map) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - for (const auto &mol : mols) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const SelectorMol &mols, const QList &idxs) + : SireBase::ConcreteProperty, SireBase::Property>() { - auto flag = SireError::exception::enableFastExceptions(); - - try + for (const auto &idx : idxs) { - this->vws.append(_get_view::get(mol, typename T::Name(name))); + this->_append(_get_view::at(mols, idx)); } - catch(...) - {} } - if (this->vws.isEmpty()) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const SelectorMol &mols, const QString &name, + const SireBase::PropertyMap &map) + : SireBase::ConcreteProperty, SireBase::Property>() { - // try a search - try + for (const auto &mol : mols) { - this->operator=(SelectorM(mols.search(name, map))); + auto flag = SireError::exception::enableFastExceptions(); + + try + { + this->vws.append(_get_view::get(mol, typename T::Name(name))); + } + catch (...) + { + } } - catch(...) + + if (this->vws.isEmpty()) { - if (name.length() < 5) - //likely a name error - _get_view::raise_missing(name); - else - //likely a syntax error - throw; + // try a search + try + { + this->operator=(SelectorM(mols.search(name, map))); + } + catch (...) + { + if (name.length() < 5) + // likely a name error + _get_view::raise_missing(name); + else + // likely a syntax error + throw; + } } } -} -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const SelectorMol &mols, const typename T::ID &id) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - for (const auto &mol : mols) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const SelectorMol &mols, const typename T::ID &id) + : SireBase::ConcreteProperty, SireBase::Property>() { - auto flag = SireError::exception::enableFastExceptions(); - - try + for (const auto &mol : mols) { - this->vws.append(_get_view::get(mol, id)); - } - catch(...) - {} - } + auto flag = SireError::exception::enableFastExceptions(); - if (this->vws.isEmpty()) - _get_view::raise_missing(id.toString()); -} + try + { + this->vws.append(_get_view::get(mol, id)); + } + catch (...) + { + } + } -template -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const SelectorM &other) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - for (const auto &o : other) - { - this->vws.append(_get_view::get(o)); + if (this->vws.isEmpty()) + _get_view::raise_missing(id.toString()); } -} -template -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const SelectorM &other, const SireBase::Slice &slice) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - for (auto it = slice.begin(_get_view::count(other)); - not it.atEnd(); it.next()) + template + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const SelectorM &other) + : SireBase::ConcreteProperty, SireBase::Property>() { - this->_append(_get_view::at(other, it.value())); + for (const auto &o : other) + { + this->vws.append(_get_view::get(o)); + } } -} -template -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const SelectorM &other, const QList &idxs) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - for (const auto &idx : idxs) + template + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const SelectorM &other, const SireBase::Slice &slice) + : SireBase::ConcreteProperty, SireBase::Property>() { - this->_append(_get_view::at(other, idx)); + for (auto it = slice.begin(_get_view::count(other)); + not it.atEnd(); it.next()) + { + this->_append(_get_view::at(other, it.value())); + } } -} -template -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const SelectorM &other, const QString &name) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - for (const auto &view : other) + template + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const SelectorM &other, const QList &idxs) + : SireBase::ConcreteProperty, SireBase::Property>() { - auto flag = SireError::exception::enableFastExceptions(); - - try + for (const auto &idx : idxs) { - this->vws.append(_get_view::get(view, name)); + this->_append(_get_view::at(other, idx)); } - catch(...) - {} } - if (this->vws.isEmpty()) + template + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const SelectorM &other, const QString &name) + : SireBase::ConcreteProperty, SireBase::Property>() { - // try a search - try + for (const auto &view : other) { - this->operator=(SelectorM(other.search(name))); + auto flag = SireError::exception::enableFastExceptions(); + + try + { + this->vws.append(_get_view::get(view, name)); + } + catch (...) + { + } } - catch(...) + + if (this->vws.isEmpty()) { - if (name.length() < 5) - //likely a name error - _get_view::raise_missing(name); - else - //likely a syntax error - throw; + // try a search + try + { + this->operator=(SelectorM(other.search(name))); + } + catch (...) + { + if (name.length() < 5) + // likely a name error + _get_view::raise_missing(name); + else + // likely a syntax error + throw; + } } } -} -template -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const SelectorM &other, const typename T::ID &id) - : SireBase::ConcreteProperty,SireBase::Property>() -{ - for (const auto &view : other) + template + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const SelectorM &other, const typename T::ID &id) + : SireBase::ConcreteProperty, SireBase::Property>() { - auto flag = SireError::exception::enableFastExceptions(); - - try + for (const auto &view : other) { - this->vws.append(_get_view::get(view, id)); - } - catch(...) - {} - } + auto flag = SireError::exception::enableFastExceptions(); - if (this->vws.isEmpty()) - _get_view::raise_missing(id.toString()); -} + try + { + this->vws.append(_get_view::get(view, id)); + } + catch (...) + { + } + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::SelectorM(const SelectorM &other) - : SireBase::ConcreteProperty,SireBase::Property>(), - vws(other.vws) -{} - -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM::~SelectorM() -{} - -template -SIRE_OUTOFLINE_TEMPLATE -const char* SelectorM::typeName() -{ - return QMetaType::typeName( qMetaTypeId< SelectorM >() ); -} + if (this->vws.isEmpty()) + _get_view::raise_missing(id.toString()); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM& SelectorM::operator=(const SelectorM &other) -{ - if (this != &other) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::SelectorM(const SelectorM &other) + : SireBase::ConcreteProperty, SireBase::Property>(), + vws(other.vws) { - this->vws = other.vws; - Property::operator=(other); } - return *this; -} - -template -SIRE_OUTOFLINE_TEMPLATE -bool SelectorM::operator==(const SelectorM &other) const -{ - return vws == other.vws; -} - -template -SIRE_OUTOFLINE_TEMPLATE -bool SelectorM::operator!=(const SelectorM &other) const -{ - return not this->operator==(other); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM::~SelectorM() + { + } -template -SIRE_OUTOFLINE_TEMPLATE -T SelectorM::operator[](int i) const -{ - i = SireID::Index(i).map(this->count()); + template + SIRE_OUTOFLINE_TEMPLATE const char *SelectorM::typeName() + { + return QMetaType::typeName(qMetaTypeId>()); + } - for (const auto &v : vws) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM & + SelectorM::operator=(const SelectorM &other) { - if (i < v.count()) - { - return v(i); - } - else + if (this != &other) { - i -= v.count(); + this->vws = other.vws; + Property::operator=(other); } + + return *this; } - throw SireError::program_bug(QObject::tr("Should not get here!"), CODELOC); + template + SIRE_OUTOFLINE_TEMPLATE bool SelectorM::operator==(const SelectorM &other) const + { + return vws == other.vws; + } - return T(); -} + template + SIRE_OUTOFLINE_TEMPLATE bool SelectorM::operator!=(const SelectorM &other) const + { + return not this->operator==(other); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::operator[](const SireBase::Slice &slice) const -{ - return SelectorM(*this, slice); -} + template + SIRE_OUTOFLINE_TEMPLATE + T + SelectorM::operator[](int i) const + { + i = SireID::Index(i).map(this->count()); -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::operator[](const QList &idxs) const -{ - return SelectorM(*this,idxs); -} + for (const auto &v : vws) + { + if (i < v.count()) + { + return v(i); + } + else + { + i -= v.count(); + } + } + throw SireError::program_bug(QObject::tr("Should not get here!"), CODELOC); -template -SIRE_OUTOFLINE_TEMPLATE -T SelectorM::operator[](const QString &name) const -{ - auto all = _get_view::getName(*this, name); + return T(); + } - if (all.count() > 1) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::operator[](const SireBase::Slice &slice) const { - _get_view::raise_duplicate(name, all.count()); + return SelectorM(*this, slice); } - BOOST_ASSERT( not all.isEmpty() ); - - return all(0); -} - -template -SIRE_OUTOFLINE_TEMPLATE -T SelectorM::operator[](const typename T::ID &id) const -{ - auto all = _get_view::getID(*this, id); - - if (all.count() > 1) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::operator[](const QList &idxs) const { - _get_view::raise_duplicate(id.toString(), all.count()); + return SelectorM(*this, idxs); } - BOOST_ASSERT( not all.isEmpty() ); - - return all(0); -} - -template -SIRE_OUTOFLINE_TEMPLATE -T SelectorM::operator()(int i) const -{ - return this->operator[](i); -} + template + SIRE_OUTOFLINE_TEMPLATE + T + SelectorM::operator[](const QString &name) const + { + auto all = _get_view::getName(*this, name); -template -SIRE_OUTOFLINE_TEMPLATE -T SelectorM::operator()(const QString &name) const -{ - return this->operator[](name); -} + if (all.count() > 1) + { + _get_view::raise_duplicate(name, all.count()); + } -template -SIRE_OUTOFLINE_TEMPLATE -T SelectorM::operator()(const typename T::ID &id) const -{ - return this->operator[](id); -} + BOOST_ASSERT(not all.isEmpty()); -template -SIRE_OUTOFLINE_TEMPLATE -QList SelectorM::toList() const -{ - QList l; - l.reserve(vws.count()); + return all(0); + } - for (const auto &v : vws) + template + SIRE_OUTOFLINE_TEMPLATE + T + SelectorM::operator[](const typename T::ID &id) const { - l.append(MolViewPtr(v.clone())); - } + auto all = _get_view::getID(*this, id); - return l; -} + if (all.count() > 1) + { + _get_view::raise_duplicate(id.toString(), all.count()); + } -template -SIRE_OUTOFLINE_TEMPLATE -Molecules SelectorM::toMolecules() const -{ - return Molecules(this->vws); -} + BOOST_ASSERT(not all.isEmpty()); -template -SIRE_OUTOFLINE_TEMPLATE -SelectResult SelectorM::toSelectResult() const -{ - return SelectResult(this->vws); -} + return all(0); + } -template -SIRE_OUTOFLINE_TEMPLATE -bool SelectorM::isSelector() const -{ - return true; -} + template + SIRE_OUTOFLINE_TEMPLATE + T + SelectorM::operator()(int i) const + { + return this->operator[](i); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::add(const SelectorM &other) const -{ - SelectorM ret(*this); + template + SIRE_OUTOFLINE_TEMPLATE + T + SelectorM::operator()(const QString &name) const + { + return this->operator[](name); + } - for (int i=0; i + SIRE_OUTOFLINE_TEMPLATE + T + SelectorM::operator()(const typename T::ID &id) const { - ret._append(other(i)); + return this->operator[](id); } - return ret; -} + template + SIRE_OUTOFLINE_TEMPLATE + QList + SelectorM::toList() const + { + QList l; + l.reserve(vws.count()); -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::add(const Selector &other) const -{ - SelectorM ret(*this); + for (const auto &v : vws) + { + l.append(MolViewPtr(v.clone())); + } - for (int i=0; i -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::add(const T &other) const -{ - SelectorM ret(*this); - ret._append(other); - return ret; -} + template + SIRE_OUTOFLINE_TEMPLATE + Molecules + SelectorM::toMolecules() const + { + return Molecules(this->vws); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::subtract(const SelectorM &other) const -{ - SelectorM ret; + template + SIRE_OUTOFLINE_TEMPLATE + SelectResult + SelectorM::toSelectResult() const + { + return SelectResult(this->vws); + } - for (const auto &view : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE + QList + SelectorM::find(const T &view) const { - auto result = view; + QList matches; + + qint64 start = 0; - for (const auto &other_view : other.vws) + for (const auto &vw : vws) { - if (result.data().number() == other_view.data().number()) + const auto m = vw.find(view); + + if (m.isEmpty()) + { + start += vw.count(); + } + else { - result = result.subtract(other_view); + matches.append(start + m[0]); + break; } } - if (not result.isEmpty()) - ret.vws.append(result); + return matches; } - return ret; -} + template + SIRE_OUTOFLINE_TEMPLATE + QList + SelectorM::find(const Selector &views) const + { + QList matches; -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::subtract(const Selector &other) const -{ - SelectorM ret; + qint64 start = 0; - for (const auto &view : this->vws) - { - if (view.data().number() == other.data().number()) + for (const auto &vw : vws) { - auto result = view.subtract(other); + const auto m = vw.find(views); - if (not result.isEmpty()) - ret.vws.append(result); + if (m.isEmpty()) + { + start += vw.count(); + } + else + { + for (auto match : m) + { + matches.append(start + match); + } + + if (matches.count() == views.count()) + break; + else + start += vw.count(); + } } - else - ret.vws.append(view); + + return matches; } - return ret; -} + template + SIRE_OUTOFLINE_TEMPLATE + QList + SelectorM::find(const SelectorM &views) const + { + QList matches; -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::subtract(const T &other) const -{ - SelectorM ret; + qint64 start = 0; - for (const auto &view : this->vws) - { - if (view.data().number() == other.data().number()) + for (const auto &view : views) { - auto result = view.subtract(other); + const auto m = this->find(view); - if (not result.isEmpty()) - ret.vws.append(result); + if (not m.isEmpty()) + { + matches += m; + } } - else - ret.vws.append(view); + + return matches; } - return ret; -} + template + QList + Selector::find(const SelectorM &views) const + { + return SelectorM(*this).find(views); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::intersection(const SelectorM &other) const -{ - SelectorM ret; + template + SIRE_OUTOFLINE_TEMPLATE bool SelectorM::isSelector() const + { + return true; + } - for (const auto &view : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::add(const SelectorM &other) const { - for (const auto &other_view : other.vws) - { - if (view.data().number() == other_view.data().number()) - { - auto intersect = view.intersection(other_view); + SelectorM ret(*this); - if (not intersect.isEmpty()) - { - ret.vws.append(intersect); - } - } + for (int i = 0; i < other.count(); ++i) + { + ret._append(other(i)); } + + return ret; } - return ret; -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::add(const Selector &other) const + { + SelectorM ret(*this); -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::intersection(const Selector &views) const -{ - SelectorM ret; + for (int i = 0; i < other.count(); ++i) + { + ret._append(other(i)); + } + + return ret; + } + + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::add(const T &other) const + { + SelectorM ret(*this); + ret._append(other); + return ret; + } - for (const auto &view : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::subtract(const SelectorM &other) const { - if (view.data().number() == view.data().number()) + SelectorM ret; + + for (const auto &view : this->vws) { - auto intersect = view.intersection(views); + auto result = view; - if (not intersect.isEmpty()) + for (const auto &other_view : other.vws) { - ret.vws.append(intersect); + if (result.data().number() == other_view.data().number()) + { + result = result.subtract(other_view); + } } + + if (not result.isEmpty()) + ret.vws.append(result); } - } - return ret; -} + return ret; + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::intersection(const T &view) const -{ - if (this->contains(view)) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::subtract(const Selector &other) const { - return SelectorM(view); - } - else - return SelectorM(); -} + SelectorM ret; -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::invert() const -{ - SelectorM ret; + for (const auto &view : this->vws) + { + if (view.data().number() == other.data().number()) + { + auto result = view.subtract(other); + + if (not result.isEmpty()) + ret.vws.append(result); + } + else + ret.vws.append(view); + } + + return ret; + } - for (const auto &view : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::subtract(const T &other) const { - auto inverted = view.invert(); + SelectorM ret; - if (not inverted.isEmpty()) + for (const auto &view : this->vws) { - ret.vws.append(inverted); + if (view.data().number() == other.data().number()) + { + auto result = view.subtract(other); + + if (not result.isEmpty()) + ret.vws.append(result); + } + else + ret.vws.append(view); } - } - return ret; -} + return ret; + } -template -SIRE_OUTOFLINE_TEMPLATE -bool SelectorM::intersects(const SelectorM &other) const -{ - for (int i=0; i + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::intersection(const SelectorM &other) const { - if (this->contains(other(i))) + SelectorM ret; + + for (const auto &view : this->vws) { - return true; + for (const auto &other_view : other.vws) + { + if (view.data().number() == other_view.data().number()) + { + auto intersect = view.intersection(other_view); + + if (not intersect.isEmpty()) + { + ret.vws.append(intersect); + } + } + } } + + return ret; } - return false; -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::intersection(const Selector &views) const + { + SelectorM ret; -template -SIRE_OUTOFLINE_TEMPLATE -bool SelectorM::intersects(const Selector &other) const -{ - for (int i=0; ivws) + { + if (view.data().number() == view.data().number()) + { + auto intersect = view.intersection(views); + + if (not intersect.isEmpty()) + { + ret.vws.append(intersect); + } + } + } + + return ret; + } + + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::intersection(const T &view) const { - if (this->contains(other(i))) + if (this->contains(view)) { - return true; + return SelectorM(view); } + else + return SelectorM(); } - return false; -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::invert() const + { + SelectorM ret; -template -SIRE_OUTOFLINE_TEMPLATE -bool SelectorM::intersects(const T &view) const -{ - return this->contains(view); -} + for (const auto &view : this->vws) + { + auto inverted = view.invert(); -template -SIRE_OUTOFLINE_TEMPLATE -bool SelectorM::contains(const SelectorM &other) const -{ - for (int i=0; i + SIRE_OUTOFLINE_TEMPLATE bool SelectorM::intersects(const SelectorM &other) const { - if (not this->contains(other(i))) + for (int i = 0; i < other.count(); ++i) { - return false; + if (this->contains(other(i))) + { + return true; + } } - } - return true; -} + return false; + } -template -SIRE_OUTOFLINE_TEMPLATE -bool SelectorM::contains(const Selector &other) const -{ - for (int i=0; i + SIRE_OUTOFLINE_TEMPLATE bool SelectorM::intersects(const Selector &other) const { - if (not this->contains(other(i))) + for (int i = 0; i < other.count(); ++i) { - return false; + if (this->contains(other(i))) + { + return true; + } } - } - return true; -} + return false; + } -template -SIRE_OUTOFLINE_TEMPLATE -bool SelectorM::contains(const T &other) const -{ - for (const auto &view : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE bool SelectorM::intersects(const T &view) const { - if (view == other) - return true; + return this->contains(view); } - return false; -} + template + SIRE_OUTOFLINE_TEMPLATE bool SelectorM::contains(const SelectorM &other) const + { + for (int i = 0; i < other.count(); ++i) + { + if (not this->contains(other(i))) + { + return false; + } + } -template -SIRE_OUTOFLINE_TEMPLATE -void SelectorM::update(const Molecules &molecules) -{ - // better to create a map from MolNum to index here - QMultiHash molnum_to_idx; - molnum_to_idx.reserve(this->vws.count()); + return true; + } + + template + SIRE_OUTOFLINE_TEMPLATE bool SelectorM::contains(const Selector &other) const + { + for (int i = 0; i < other.count(); ++i) + { + if (not this->contains(other(i))) + { + return false; + } + } - int i = 0; + return true; + } - for (const auto &view : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE bool SelectorM::contains(const T &other) const { - molnum_to_idx.insert(view.data().number(), i); - i += 1; + for (const auto &view : this->vws) + { + if (view == other) + return true; + } + + return false; } - for (const auto &mol : molecules) + template + SIRE_OUTOFLINE_TEMPLATE void SelectorM::update(const Molecules &molecules) { - const auto molnum = mol.data().number(); + // better to create a map from MolNum to index here + QMultiHash molnum_to_idx; + molnum_to_idx.reserve(this->vws.count()); - auto it = molnum_to_idx.constFind(molnum); + int i = 0; - while (it != molnum_to_idx.constEnd() && it.key() == molnum) + for (const auto &view : this->vws) { - this->vws[it.value()].update(mol.data()); + molnum_to_idx.insert(view.data().number(), i); + i += 1; } - } -} -template -SIRE_OUTOFLINE_TEMPLATE -SelectResult SelectorM::search(const QString &search_term) const -{ - Select search(search_term); - return search(this->toSelectResult()); -} + for (const auto &mol : molecules) + { + const auto molnum = mol.data().number(); -template -SIRE_OUTOFLINE_TEMPLATE -SelectResult SelectorM::search(const QString &search_term, - const SireBase::PropertyMap &map) const -{ - Select search(search_term); - return search(this->toSelectResult(), map); -} + auto it = molnum_to_idx.constFind(molnum); -template -SIRE_OUTOFLINE_TEMPLATE -int SelectorM::count() const -{ - int n = 0; + while (it != molnum_to_idx.constEnd() && it.key() == molnum) + { + this->vws[it.value()].update(mol.data()); + } + } + } - for (const auto &v : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE + SelectResult + SelectorM::search(const QString &search_term) const { - n += v.count(); + Select search(search_term); + return search(this->toSelectResult()); } - return n; -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectResult + SelectorM::search(const QString &search_term, + const SireBase::PropertyMap &map) const + { + Select search(search_term); + return search(this->toSelectResult(), map); + } -template -SIRE_OUTOFLINE_TEMPLATE -int SelectorM::size() const -{ - return this->count(); -} + template + SIRE_OUTOFLINE_TEMPLATE int SelectorM::count() const + { + int n = 0; -template -SIRE_OUTOFLINE_TEMPLATE -MoleculeGroup SelectorM::toMoleculeGroup() const -{ - MoleculeGroup grp; + for (const auto &v : this->vws) + { + n += v.count(); + } + + return n; + } - for (const auto &view : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE int SelectorM::size() const { - grp.add(view); + return this->count(); } - return grp; -} + template + SIRE_OUTOFLINE_TEMPLATE + MoleculeGroup + SelectorM::toMoleculeGroup() const + { + MoleculeGroup grp; -template -SIRE_OUTOFLINE_TEMPLATE -Molecule SelectorM::molecule(int i, - const SireBase::PropertyMap&) const -{ - i = SireID::Index(i).map(this->vws.count()); + for (const auto &view : this->vws) + { + grp.add(view); + } - return this->vws.at(i).molecule(); -} + return grp; + } -template -SIRE_OUTOFLINE_TEMPLATE -Molecule SelectorM::molecule(const QString &name, - const SireBase::PropertyMap &map) const -{ - auto mols = this->molecules(name, map); + template + SIRE_OUTOFLINE_TEMPLATE + Molecule + SelectorM::molecule(int i, + const SireBase::PropertyMap &) const + { + i = SireID::Index(i).map(this->vws.count()); - if (mols.count() > 1) - throw SireMol::duplicate_molecule(QObject::tr( - "More than one molecule matches '%1'. Number of matches is %2.") - .arg(name).arg(mols.count()), CODELOC); + return this->vws.at(i).molecule(); + } - BOOST_ASSERT(not mols.isEmpty()); + template + SIRE_OUTOFLINE_TEMPLATE + Molecule + SelectorM::molecule(const QString &name, + const SireBase::PropertyMap &map) const + { + auto mols = this->molecules(name, map); - return mols[0]; -} + if (mols.count() > 1) + throw SireMol::duplicate_molecule(QObject::tr( + "More than one molecule matches '%1'. Number of matches is %2.") + .arg(name) + .arg(mols.count()), + CODELOC); -template -SIRE_OUTOFLINE_TEMPLATE -Molecule SelectorM::molecule(const MolID &molid, - const SireBase::PropertyMap &map) -{ - auto mols = this->molecules(molid, map); + BOOST_ASSERT(not mols.isEmpty()); - if (mols.count() > 1) - throw SireMol::duplicate_molecule(QObject::tr( - "More than one molecule matches '%1'. Number of matches is %2.") - .arg(molid.toString()).arg(mols.count()), CODELOC); + return mols[0]; + } - BOOST_ASSERT(not mols.isEmpty()); + template + SIRE_OUTOFLINE_TEMPLATE + Molecule + SelectorM::molecule(const MolID &molid, + const SireBase::PropertyMap &map) + { + auto mols = this->molecules(molid, map); - return mols[0]; -} + if (mols.count() > 1) + throw SireMol::duplicate_molecule(QObject::tr( + "More than one molecule matches '%1'. Number of matches is %2.") + .arg(molid.toString()) + .arg(mols.count()), + CODELOC); -template -SIRE_OUTOFLINE_TEMPLATE -SelectorMol SelectorM::molecules() const -{ - return SelectorMol(*this); -} + BOOST_ASSERT(not mols.isEmpty()); -template -SIRE_OUTOFLINE_TEMPLATE -SelectorMol SelectorM::molecules(int i, - const SireBase::PropertyMap &map) const -{ - return SelectorMol(this->molecule(i, map)); -} + return mols[0]; + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorMol SelectorM::molecules(const SireBase::Slice &slice, - const SireBase::PropertyMap&) const -{ - return SelectorMol(*this, slice); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorMol + SelectorM::molecules() const + { + return SelectorMol(*this); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorMol SelectorM::molecules(const QList &idxs, - const SireBase::PropertyMap&) const -{ - return SelectorMol(*this, idxs); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorMol + SelectorM::molecules(int i, + const SireBase::PropertyMap &map) const + { + return SelectorMol(this->molecule(i, map)); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorMol SelectorM::molecules(const QString &name, - const SireBase::PropertyMap &map) const -{ - return SelectorMol(*this, name, map); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorMol + SelectorM::molecules(const SireBase::Slice &slice, + const SireBase::PropertyMap &) const + { + return SelectorMol(*this, slice); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorMol SelectorM::molecules(const MolID &molid, - const SireBase::PropertyMap&) const -{ - return SelectorMol(*this, molid); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorMol + SelectorM::molecules(const QList &idxs, + const SireBase::PropertyMap &) const + { + return SelectorMol(*this, idxs); + } -template -SIRE_OUTOFLINE_TEMPLATE -Atom SelectorM::atom(int i, const SireBase::PropertyMap&) const -{ - i = SireID::Index(i).map(this->nAtoms()); + template + SIRE_OUTOFLINE_TEMPLATE + SelectorMol + SelectorM::molecules(const QString &name, + const SireBase::PropertyMap &map) const + { + return SelectorMol(*this, name, map); + } - for (const auto &v : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorMol + SelectorM::molecules(const MolID &molid, + const SireBase::PropertyMap &) const { - if (i < v.nAtoms()) - { - return v.atom(i); - } - else - { - i -= v.nAtoms(); - } + return SelectorMol(*this, molid); } - throw SireError::program_bug(QObject::tr("Should not get here!"), CODELOC); + template + SIRE_OUTOFLINE_TEMPLATE + Atom + SelectorM::atom(int i, const SireBase::PropertyMap &) const + { + i = SireID::Index(i).map(this->nAtoms()); - return Atom(); -} + for (const auto &v : this->vws) + { + if (i < v.nAtoms()) + { + return v.atom(i); + } + else + { + i -= v.nAtoms(); + } + } -template -SIRE_OUTOFLINE_TEMPLATE -Atom SelectorM::atom(const QString &name, - const SireBase::PropertyMap &map) const -{ - auto all = this->atoms(name, map); + throw SireError::program_bug(QObject::tr("Should not get here!"), CODELOC); + + return Atom(); + } - if (all.count() > 1) - _get_view::raise_duplicate(name, all.count()); + template + SIRE_OUTOFLINE_TEMPLATE + Atom + SelectorM::atom(const QString &name, + const SireBase::PropertyMap &map) const + { + auto all = this->atoms(name, map); - BOOST_ASSERT( not all.isEmpty() ); + if (all.count() > 1) + _get_view::raise_duplicate(name, all.count()); - return all[0]; -} + BOOST_ASSERT(not all.isEmpty()); -template -SIRE_OUTOFLINE_TEMPLATE -Atom SelectorM::atom(const AtomID &atomid, - const SireBase::PropertyMap &map) const -{ - auto all = this->atoms(atomid, map); + return all[0]; + } - if (all.count() > 1) - _get_view::raise_duplicate(atomid.toString(), all.count()); + template + SIRE_OUTOFLINE_TEMPLATE + Atom + SelectorM::atom(const AtomID &atomid, + const SireBase::PropertyMap &map) const + { + auto all = this->atoms(atomid, map); - BOOST_ASSERT( not all.isEmpty() ); + if (all.count() > 1) + _get_view::raise_duplicate(atomid.toString(), all.count()); - return all[0]; -} + BOOST_ASSERT(not all.isEmpty()); -template -SIRE_OUTOFLINE_TEMPLATE -Residue SelectorM::residue(int i, const SireBase::PropertyMap&) const -{ - i = SireID::Index(i).map(this->nResidues()); + return all[0]; + } - for (const auto &v : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE + Residue + SelectorM::residue(int i, const SireBase::PropertyMap &) const { - if (i < v.nResidues()) - { - return v.residue(i); - } - else + i = SireID::Index(i).map(this->nResidues()); + + for (const auto &v : this->vws) { - i -= v.nResidues(); + if (i < v.nResidues()) + { + return v.residue(i); + } + else + { + i -= v.nResidues(); + } } - } - throw SireError::program_bug(QObject::tr("Should not get here!"), CODELOC); + throw SireError::program_bug(QObject::tr("Should not get here!"), CODELOC); - return Residue(); -} + return Residue(); + } -template -SIRE_OUTOFLINE_TEMPLATE -Residue SelectorM::residue(const QString &name, + template + SIRE_OUTOFLINE_TEMPLATE + Residue + SelectorM::residue(const QString &name, const SireBase::PropertyMap &map) const -{ - auto all = this->residues(name, map); + { + auto all = this->residues(name, map); - if (all.count() > 1) - _get_view::raise_duplicate(name, all.count()); + if (all.count() > 1) + _get_view::raise_duplicate(name, all.count()); - BOOST_ASSERT( not all.isEmpty() ); + BOOST_ASSERT(not all.isEmpty()); - return all[0]; -} + return all[0]; + } -template -SIRE_OUTOFLINE_TEMPLATE -Residue SelectorM::residue(const ResID &resid, + template + SIRE_OUTOFLINE_TEMPLATE + Residue + SelectorM::residue(const ResID &resid, const SireBase::PropertyMap &map) const -{ - auto all = this->residues(resid, map); - - if (all.count() > 1) - _get_view::raise_duplicate(resid.toString(), all.count()); + { + auto all = this->residues(resid, map); - BOOST_ASSERT( not all.isEmpty() ); + if (all.count() > 1) + _get_view::raise_duplicate(resid.toString(), all.count()); - return all[0]; -} + BOOST_ASSERT(not all.isEmpty()); -template -SIRE_OUTOFLINE_TEMPLATE -Chain SelectorM::chain(int i, const SireBase::PropertyMap&) const -{ - i = SireID::Index(i).map(this->nChains()); + return all[0]; + } - for (const auto &v : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE + Chain + SelectorM::chain(int i, const SireBase::PropertyMap &) const { - if (i < v.nChains()) - { - return v.chain(i); - } - else + i = SireID::Index(i).map(this->nChains()); + + for (const auto &v : this->vws) { - i -= v.nChains(); + if (i < v.nChains()) + { + return v.chain(i); + } + else + { + i -= v.nChains(); + } } - } - throw SireError::program_bug(QObject::tr("Should not get here!"), CODELOC); + throw SireError::program_bug(QObject::tr("Should not get here!"), CODELOC); - return Chain(); -} + return Chain(); + } -template -SIRE_OUTOFLINE_TEMPLATE -Chain SelectorM::chain(const QString &name, - const SireBase::PropertyMap &map) const -{ - auto all = this->chains(name, map); + template + SIRE_OUTOFLINE_TEMPLATE + Chain + SelectorM::chain(const QString &name, + const SireBase::PropertyMap &map) const + { + auto all = this->chains(name, map); - if (all.count() > 1) - _get_view::raise_duplicate(name, all.count()); + if (all.count() > 1) + _get_view::raise_duplicate(name, all.count()); - BOOST_ASSERT( not all.isEmpty() ); + BOOST_ASSERT(not all.isEmpty()); - return all[0]; -} + return all[0]; + } -template -SIRE_OUTOFLINE_TEMPLATE -Chain SelectorM::chain(const ChainID &chainid, - const SireBase::PropertyMap &map) const -{ - auto all = this->chains(chainid); + template + SIRE_OUTOFLINE_TEMPLATE + Chain + SelectorM::chain(const ChainID &chainid, + const SireBase::PropertyMap &map) const + { + auto all = this->chains(chainid); - if (all.count() > 1) - _get_view::raise_duplicate(chainid.toString(), all.count()); + if (all.count() > 1) + _get_view::raise_duplicate(chainid.toString(), all.count()); - BOOST_ASSERT( not all.isEmpty() ); + BOOST_ASSERT(not all.isEmpty()); - return all[0]; -} - -template -SIRE_OUTOFLINE_TEMPLATE -Segment SelectorM::segment(int i, const SireBase::PropertyMap&) const -{ - i = SireID::Index(i).map(this->nSegments()); + return all[0]; + } - for (const auto &v : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE + Segment + SelectorM::segment(int i, const SireBase::PropertyMap &) const { - if (i < v.nSegments()) - { - return v.segment(i); - } - else + i = SireID::Index(i).map(this->nSegments()); + + for (const auto &v : this->vws) { - i -= v.nSegments(); + if (i < v.nSegments()) + { + return v.segment(i); + } + else + { + i -= v.nSegments(); + } } - } - throw SireError::program_bug(QObject::tr("Should not get here!"), CODELOC); + throw SireError::program_bug(QObject::tr("Should not get here!"), CODELOC); - return Segment(); -} + return Segment(); + } -template -SIRE_OUTOFLINE_TEMPLATE -Segment SelectorM::segment(const QString &name, + template + SIRE_OUTOFLINE_TEMPLATE + Segment + SelectorM::segment(const QString &name, const SireBase::PropertyMap &map) const -{ - auto all = this->segments(name, map); + { + auto all = this->segments(name, map); - if (all.count() > 1) - _get_view::raise_duplicate(name, all.count()); + if (all.count() > 1) + _get_view::raise_duplicate(name, all.count()); - BOOST_ASSERT( not all.isEmpty() ); + BOOST_ASSERT(not all.isEmpty()); - return all[0]; -} + return all[0]; + } -template -SIRE_OUTOFLINE_TEMPLATE -Segment SelectorM::segment(const SegID &segid, + template + SIRE_OUTOFLINE_TEMPLATE + Segment + SelectorM::segment(const SegID &segid, const SireBase::PropertyMap &map) const -{ - auto all = this->segments(segid, map); + { + auto all = this->segments(segid, map); - if (all.count() > 1) - _get_view::raise_duplicate(segid.toString(), all.count()); + if (all.count() > 1) + _get_view::raise_duplicate(segid.toString(), all.count()); - BOOST_ASSERT( not all.isEmpty() ); + BOOST_ASSERT(not all.isEmpty()); - return all[0]; -} - -template -SIRE_OUTOFLINE_TEMPLATE -CutGroup SelectorM::cutGroup(int i, const SireBase::PropertyMap&) const -{ - i = SireID::Index(i).map(this->nCutGroups()); + return all[0]; + } - for (const auto &v : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE + CutGroup + SelectorM::cutGroup(int i, const SireBase::PropertyMap &) const { - if (i < v.nCutGroups()) - { - return v.cutGroup(i); - } - else + i = SireID::Index(i).map(this->nCutGroups()); + + for (const auto &v : this->vws) { - i -= v.nCutGroups(); + if (i < v.nCutGroups()) + { + return v.cutGroup(i); + } + else + { + i -= v.nCutGroups(); + } } - } - - throw SireError::program_bug(QObject::tr("Should not get here!"), CODELOC); - return CutGroup(); -} - -template -SIRE_OUTOFLINE_TEMPLATE -CutGroup SelectorM::cutGroup(const QString &name, - const SireBase::PropertyMap &map) const -{ - auto all = this->cutGroups(name, map); + throw SireError::program_bug(QObject::tr("Should not get here!"), CODELOC); - if (all.count() > 1) - _get_view::raise_duplicate(name, all.count()); + return CutGroup(); + } - BOOST_ASSERT( not all.isEmpty() ); + template + SIRE_OUTOFLINE_TEMPLATE + CutGroup + SelectorM::cutGroup(const QString &name, + const SireBase::PropertyMap &map) const + { + auto all = this->cutGroups(name, map); - return all[0]; -} + if (all.count() > 1) + _get_view::raise_duplicate(name, all.count()); -template -SIRE_OUTOFLINE_TEMPLATE -CutGroup SelectorM::cutGroup(const CGID &cgid, - const SireBase::PropertyMap &map) const -{ - auto all = this->cutGroups(cgid, map); + BOOST_ASSERT(not all.isEmpty()); - if (all.count() > 1) - _get_view::raise_duplicate(cgid.toString(), all.count()); + return all[0]; + } - BOOST_ASSERT( not all.isEmpty() ); + template + SIRE_OUTOFLINE_TEMPLATE + CutGroup + SelectorM::cutGroup(const CGID &cgid, + const SireBase::PropertyMap &map) const + { + auto all = this->cutGroups(cgid, map); - return all[0]; -} + if (all.count() > 1) + _get_view::raise_duplicate(cgid.toString(), all.count()); -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::atoms() const -{ - return SelectorM(*this); -} + BOOST_ASSERT(not all.isEmpty()); -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::atoms(int i, const SireBase::PropertyMap &map) const -{ - return SelectorM(this->atom(i,map)); -} + return all[0]; + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::atoms(const SireBase::Slice &slice, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, slice); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::atoms() const + { + return SelectorM(*this); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::atoms(const QList &idxs, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, idxs); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::atoms(int i, const SireBase::PropertyMap &map) const + { + return SelectorM(this->atom(i, map)); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::atoms(const QString &name, - const SireBase::PropertyMap &map) const -{ - return SelectorM(*this, name, map); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::atoms(const SireBase::Slice &slice, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, slice); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::atoms(const AtomID &atomid, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, atomid); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::atoms(const QList &idxs, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, idxs); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::residues() const -{ - return SelectorM(*this); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::atoms(const QString &name, + const SireBase::PropertyMap &map) const + { + return SelectorM(*this, name, map); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::residues(int i, - const SireBase::PropertyMap &map) const -{ - return SelectorM(this->residue(i, map)); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::atoms(const AtomID &atomid, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, atomid); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::residues(const SireBase::Slice &slice, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, slice); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::residues() const + { + return SelectorM(*this); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::residues(const QList &idxs, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, idxs); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::residues(int i, + const SireBase::PropertyMap &map) const + { + return SelectorM(this->residue(i, map)); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::residues(const QString &name, - const SireBase::PropertyMap &map) const -{ - return SelectorM(*this, name, map); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::residues(const SireBase::Slice &slice, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, slice); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::residues(const ResID &resid, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, resid); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::residues(const QList &idxs, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, idxs); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::chains() const -{ - return SelectorM(*this); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::residues(const QString &name, + const SireBase::PropertyMap &map) const + { + return SelectorM(*this, name, map); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::chains(int i, - const SireBase::PropertyMap &map) const -{ - return SelectorM(this->chain(i, map)); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::residues(const ResID &resid, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, resid); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::chains(const SireBase::Slice &slice, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, slice); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::chains() const + { + return SelectorM(*this); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::chains(const QList &idxs, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, idxs); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::chains(int i, + const SireBase::PropertyMap &map) const + { + return SelectorM(this->chain(i, map)); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::chains(const QString &name, - const SireBase::PropertyMap &map) const -{ - return SelectorM(*this, name, map); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::chains(const SireBase::Slice &slice, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, slice); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::chains(const ChainID &chainid, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, chainid); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::chains(const QList &idxs, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, idxs); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::segments() const -{ - return SelectorM(*this); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::chains(const QString &name, + const SireBase::PropertyMap &map) const + { + return SelectorM(*this, name, map); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::segments(int i, - const SireBase::PropertyMap &map) const -{ - return SelectorM(this->segment(i, map)); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::chains(const ChainID &chainid, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, chainid); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::segments(const SireBase::Slice &slice, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, slice); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::segments() const + { + return SelectorM(*this); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::segments(const QList &idxs, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, idxs); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::segments(int i, + const SireBase::PropertyMap &map) const + { + return SelectorM(this->segment(i, map)); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::segments(const QString &name, - const SireBase::PropertyMap &map) const -{ - return SelectorM(*this, name, map); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::segments(const SireBase::Slice &slice, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, slice); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::segments(const SegID &segid, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, segid); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::segments(const QList &idxs, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, idxs); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::cutGroups() const -{ - return SelectorM(*this); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::segments(const QString &name, + const SireBase::PropertyMap &map) const + { + return SelectorM(*this, name, map); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::cutGroups(int i, - const SireBase::PropertyMap &map) const -{ - return SelectorM(this->cutGroup(i, map)); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::segments(const SegID &segid, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, segid); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::cutGroups(const SireBase::Slice &slice, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, slice); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::cutGroups() const + { + return SelectorM(*this); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::cutGroups(const QList &idxs, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, idxs); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::cutGroups(int i, + const SireBase::PropertyMap &map) const + { + return SelectorM(this->cutGroup(i, map)); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::cutGroups(const QString &name, - const SireBase::PropertyMap &map) const -{ - return SelectorM(*this, name, map); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::cutGroups(const SireBase::Slice &slice, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, slice); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorM SelectorM::cutGroups(const CGID &cgid, - const SireBase::PropertyMap&) const -{ - return SelectorM(*this, cgid); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::cutGroups(const QList &idxs, + const SireBase::PropertyMap &) const + { + return SelectorM(*this, idxs); + } -template -SIRE_OUTOFLINE_TEMPLATE -QList SelectorM::IDs() const -{ - QList ids; + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::cutGroups(const QString &name, + const SireBase::PropertyMap &map) const + { + return SelectorM(*this, name, map); + } - for (const auto &v : this->vws) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorM + SelectorM::cutGroups(const CGID &cgid, + const SireBase::PropertyMap &) const { - ids += v.IDs(); + return SelectorM(*this, cgid); } - return ids; -} + template + SIRE_OUTOFLINE_TEMPLATE + QList + SelectorM::IDs() const + { + QList ids; -template -SIRE_OUTOFLINE_TEMPLATE -QList SelectorM::indexes() const -{ - QList idxs; + for (const auto &v : this->vws) + { + ids += v.IDs(); + } - for (const auto &v : this->vws) - { - idxs += v.indexes(); + return ids; } - return idxs; -} + template + SIRE_OUTOFLINE_TEMPLATE + QList + SelectorM::indexes() const + { + QList idxs; -template -SIRE_OUTOFLINE_TEMPLATE -QList SelectorM::numbers() const -{ - QList nums; + for (const auto &v : this->vws) + { + idxs += v.indexes(); + } - for (const auto &v : this->vws) - { - nums += v.numbers(); + return idxs; } - return nums; -} + template + SIRE_OUTOFLINE_TEMPLATE + QList + SelectorM::numbers() const + { + QList nums; -template -SIRE_OUTOFLINE_TEMPLATE -QList SelectorM::names() const -{ - QList nmes; + for (const auto &v : this->vws) + { + nums += v.numbers(); + } - for (const auto &v : this->vws) - { - nmes += v.names(); + return nums; } - return nmes; -} + template + SIRE_OUTOFLINE_TEMPLATE + QList + SelectorM::names() const + { + QList nmes; -template -SIRE_OUTOFLINE_TEMPLATE -int SelectorM::nAtoms() const -{ - int n = 0; + for (const auto &v : this->vws) + { + nmes += v.names(); + } - for (const auto &v : this->vws) - { - n += v.nAtoms(); + return nmes; } - return n; -} + template + SIRE_OUTOFLINE_TEMPLATE int SelectorM::nAtoms() const + { + int n = 0; -template -SIRE_OUTOFLINE_TEMPLATE -int SelectorM::nResidues() const -{ - int n = 0; + for (const auto &v : this->vws) + { + n += v.nAtoms(); + } - for (const auto &v : this->vws) - { - n += v.nResidues(); + return n; } - return n; -} + template + SIRE_OUTOFLINE_TEMPLATE int SelectorM::nResidues() const + { + int n = 0; -template -SIRE_OUTOFLINE_TEMPLATE -int SelectorM::nChains() const -{ - int n = 0; + for (const auto &v : this->vws) + { + n += v.nResidues(); + } - for (const auto &v : this->vws) - { - n += v.nChains(); + return n; } - return n; -} + template + SIRE_OUTOFLINE_TEMPLATE int SelectorM::nChains() const + { + int n = 0; -template -SIRE_OUTOFLINE_TEMPLATE -int SelectorM::nSegments() const -{ - int n = 0; + for (const auto &v : this->vws) + { + n += v.nChains(); + } - for (const auto &v : this->vws) - { - n += v.nSegments(); + return n; } - return n; -} + template + SIRE_OUTOFLINE_TEMPLATE int SelectorM::nSegments() const + { + int n = 0; -template -SIRE_OUTOFLINE_TEMPLATE -int SelectorM::nCutGroups() const -{ - int n = 0; + for (const auto &v : this->vws) + { + n += v.nSegments(); + } - for (const auto &v : this->vws) - { - n += v.nCutGroups(); + return n; } - return n; -} - -template -SIRE_OUTOFLINE_TEMPLATE -int SelectorM::nMolecules() const -{ - return this->vws.count(); -} + template + SIRE_OUTOFLINE_TEMPLATE int SelectorM::nCutGroups() const + { + int n = 0; -template -SIRE_OUTOFLINE_TEMPLATE -int SelectorM::nFrames() const -{ - return this->nFrames(PropertyMap()); -} + for (const auto &v : this->vws) + { + n += v.nCutGroups(); + } -template -SIRE_OUTOFLINE_TEMPLATE -int SelectorM::nFrames(const SireBase::PropertyMap &map) const -{ - return SireMol::detail::_nFrames(this->vws, map); -} + return n; + } -template -SIRE_OUTOFLINE_TEMPLATE -void SelectorM::loadFrame(int frame) -{ - this->loadFrame(frame, PropertyMap()); -} + template + SIRE_OUTOFLINE_TEMPLATE int SelectorM::nMolecules() const + { + return this->vws.count(); + } -template -SIRE_OUTOFLINE_TEMPLATE -void SelectorM::saveFrame(int frame) -{ - this->saveFrame(frame, PropertyMap()); -} + template + SIRE_OUTOFLINE_TEMPLATE int SelectorM::nFrames() const + { + return this->nFrames(PropertyMap()); + } -template -SIRE_OUTOFLINE_TEMPLATE -void SelectorM::saveFrame() -{ - this->saveFrame(PropertyMap()); -} + template + SIRE_OUTOFLINE_TEMPLATE int SelectorM::nFrames(const SireBase::PropertyMap &map) const + { + return SireMol::detail::_nFrames(this->vws, map); + } -template -SIRE_OUTOFLINE_TEMPLATE -void SelectorM::deleteFrame(int frame) -{ - this->deleteFrame(frame, PropertyMap()); -} + template + SIRE_OUTOFLINE_TEMPLATE void SelectorM::loadFrame(int frame) + { + this->loadFrame(frame, PropertyMap()); + } -template -SIRE_OUTOFLINE_TEMPLATE -void SelectorM::loadFrame(int frame, const SireBase::PropertyMap &map) -{ - SireMol::detail::_loadFrame(this->vws, frame, map); -} + template + SIRE_OUTOFLINE_TEMPLATE void SelectorM::saveFrame(int frame) + { + this->saveFrame(frame, PropertyMap()); + } -template -SIRE_OUTOFLINE_TEMPLATE -void SelectorM::saveFrame(int frame, const SireBase::PropertyMap &map) -{ - SireMol::detail::_saveFrame(this->vws, frame, map); -} + template + SIRE_OUTOFLINE_TEMPLATE void SelectorM::saveFrame() + { + this->saveFrame(PropertyMap()); + } -template -SIRE_OUTOFLINE_TEMPLATE -void SelectorM::saveFrame(const SireBase::PropertyMap &map) -{ - SireMol::detail::_saveFrame(this->vws, map); -} + template + SIRE_OUTOFLINE_TEMPLATE void SelectorM::deleteFrame(int frame) + { + this->deleteFrame(frame, PropertyMap()); + } -template -SIRE_OUTOFLINE_TEMPLATE -void SelectorM::deleteFrame(int frame, const SireBase::PropertyMap &map) -{ - SireMol::detail::_deleteFrame(this->vws, frame, map); -} + template + SIRE_OUTOFLINE_TEMPLATE void SelectorM::loadFrame(int frame, const SireBase::PropertyMap &map) + { + SireMol::detail::_loadFrame(this->vws, frame, map); + } -template -SIRE_OUTOFLINE_TEMPLATE -bool SelectorM::isEmpty() const -{ - return this->vws.isEmpty(); -} + template + SIRE_OUTOFLINE_TEMPLATE void SelectorM::saveFrame(int frame, const SireBase::PropertyMap &map) + { + SireMol::detail::_saveFrame(this->vws, frame, map); + } -template -SIRE_OUTOFLINE_TEMPLATE -typename SelectorM::const_iterator SelectorM::begin() const -{ - return this->vws.constBegin(); -} + template + SIRE_OUTOFLINE_TEMPLATE void SelectorM::saveFrame(const SireBase::PropertyMap &map) + { + SireMol::detail::_saveFrame(this->vws, map); + } -template -SIRE_OUTOFLINE_TEMPLATE -typename SelectorM::const_iterator SelectorM::end() const -{ - return this->vws.constEnd(); -} + template + SIRE_OUTOFLINE_TEMPLATE void SelectorM::deleteFrame(int frame, const SireBase::PropertyMap &map) + { + SireMol::detail::_deleteFrame(this->vws, frame, map); + } -template -SIRE_OUTOFLINE_TEMPLATE -typename SelectorM::const_iterator SelectorM::constBegin() const -{ - return this->vws.constBegin(); -} + template + SIRE_OUTOFLINE_TEMPLATE bool SelectorM::isEmpty() const + { + return this->vws.isEmpty(); + } -template -SIRE_OUTOFLINE_TEMPLATE -typename SelectorM::const_iterator SelectorM::constEnd() const -{ - return this->vws.constEnd(); -} + template + SIRE_OUTOFLINE_TEMPLATE + typename SelectorM::const_iterator + SelectorM::begin() const + { + return this->vws.constBegin(); + } -template -SIRE_OUTOFLINE_TEMPLATE -QString SelectorM::toString() const -{ - if (this->isEmpty()) + template + SIRE_OUTOFLINE_TEMPLATE + typename SelectorM::const_iterator + SelectorM::end() const { - return QObject::tr("%1::empty").arg(this->what()); + return this->vws.constEnd(); } - else + + template + SIRE_OUTOFLINE_TEMPLATE + typename SelectorM::const_iterator + SelectorM::constBegin() const { - QStringList parts; + return this->vws.constBegin(); + } - const auto n = this->count(); + template + SIRE_OUTOFLINE_TEMPLATE + typename SelectorM::const_iterator + SelectorM::constEnd() const + { + return this->vws.constEnd(); + } - if (n <= 10) + template + SIRE_OUTOFLINE_TEMPLATE + QString + SelectorM::toString() const + { + if (this->isEmpty()) { - for (int i=0; ioperator[](i); - - parts.append(QString("%1: %2 %3") - .arg(i).arg(view.data().number().toString()) - .arg(view.toString())); - } + return QObject::tr("%1::empty").arg(this->what()); } else { - for (int i=0; i<5; ++i) + QStringList parts; + + const auto n = this->count(); + + if (n <= 10) { - const auto view = this->operator[](i); + for (int i = 0; i < n; ++i) + { + const auto view = this->operator[](i); - parts.append(QString("%1: %2 %3") - .arg(i).arg(view.data().number().toString()) - .arg(view.toString())); + parts.append(QString("%1: %2 %3") + .arg(i) + .arg(view.data().number().toString()) + .arg(view.toString())); + } } + else + { + for (int i = 0; i < 5; ++i) + { + const auto view = this->operator[](i); - parts.append("..."); + parts.append(QString("%1: %2 %3") + .arg(i) + .arg(view.data().number().toString()) + .arg(view.toString())); + } - for (int i=n-5; ioperator[](i); + parts.append("..."); + + for (int i = n - 5; i < n; ++i) + { + const auto view = this->operator[](i); - parts.append(QString("%1: %2 %3") - .arg(i).arg(view.data().number().toString()) - .arg(view.toString())); + parts.append(QString("%1: %2 %3") + .arg(i) + .arg(view.data().number().toString()) + .arg(view.toString())); + } } - } - return QObject::tr("%1( size=%2\n%3\n)") - .arg(this->what()).arg(n) - .arg(parts.join("\n")); + return QObject::tr("%1( size=%2\n%3\n)") + .arg(this->what()) + .arg(n) + .arg(parts.join("\n")); + } } -} #endif // SIRE_SKIP_INLINE_FUNCTIONS @@ -2497,25 +2677,26 @@ QString SelectorM::toString() const namespace SireMol { -template -SIRE_OUTOFLINE_TEMPLATE -EvaluatorM::EvaluatorM(const SelectorM &views) - : SireBase::ConcreteProperty() -{ - this->vws.reserve(views.count()); - - for (const auto &view : views) + template + SIRE_OUTOFLINE_TEMPLATE + EvaluatorM::EvaluatorM(const SelectorM &views) + : SireBase::ConcreteProperty() { - this->vws.append(PartialMolecule(view)); + this->vws.reserve(views.count()); + + for (const auto &view : views) + { + this->vws.append(PartialMolecule(view)); + } } -} -template -SIRE_OUTOFLINE_TEMPLATE -EvaluatorM SelectorM::evaluate() const -{ - return EvaluatorM(*this); -} + template + SIRE_OUTOFLINE_TEMPLATE + EvaluatorM + SelectorM::evaluate() const + { + return EvaluatorM(*this); + } } // end of namespace SireMol diff --git a/corelib/src/libs/SireMol/selectormol.cpp b/corelib/src/libs/SireMol/selectormol.cpp index 95b4cc5ca..5aea86ee8 100644 --- a/corelib/src/libs/SireMol/selectormol.cpp +++ b/corelib/src/libs/SireMol/selectormol.cpp @@ -56,11 +56,11 @@ using namespace SireMol; using namespace SireID; RegisterMetaType r_smol; -RegisterMetaType< SelectorM > r_satm; -RegisterMetaType< SelectorM > r_sres; -RegisterMetaType< SelectorM > r_schn; -RegisterMetaType< SelectorM > r_sseg; -RegisterMetaType< SelectorM > r_scg; +RegisterMetaType> r_satm; +RegisterMetaType> r_sres; +RegisterMetaType> r_schn; +RegisterMetaType> r_sseg; +RegisterMetaType> r_scg; /** Serialise to a binary datastream */ SIREMOL_EXPORT QDataStream &operator<<(QDataStream &ds, const SelectorMol &mols) @@ -69,7 +69,7 @@ SIREMOL_EXPORT QDataStream &operator<<(QDataStream &ds, const SelectorMol &mols) SharedDataStream sds(ds); - sds << mols.mols << static_cast(mols); + sds << mols.mols << static_cast(mols); return ds; } @@ -82,7 +82,7 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorMol &mols) if (v == 1) { SharedDataStream sds(ds); - sds >> mols.mols >> static_cast(mols); + sds >> mols.mols >> static_cast(mols); } else throw version_error(v, "1", r_smol, CODELOC); @@ -91,20 +91,20 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorMol &mols) } /** Serialise to a binary datastream */ -template<> +template <> SIREMOL_EXPORT QDataStream &operator<<(QDataStream &ds, const SelectorM &mols) { writeHeader(ds, r_satm, 1); SharedDataStream sds(ds); - sds << mols.vws << static_cast(mols); + sds << mols.vws << static_cast(mols); return ds; } /** Extract from a binary datastream */ -template<> +template <> SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mols) { VersionID v = readHeader(ds, r_satm); @@ -112,7 +112,7 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mols) if (v == 1) { SharedDataStream sds(ds); - sds >> mols.vws >> static_cast(mols); + sds >> mols.vws >> static_cast(mols); } else throw version_error(v, "1", r_satm, CODELOC); @@ -120,20 +120,20 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mols) return ds; } /** Serialise to a binary datastream */ -template<> +template <> SIREMOL_EXPORT QDataStream &operator<<(QDataStream &ds, const SelectorM &mols) { writeHeader(ds, r_sres, 1); SharedDataStream sds(ds); - sds << mols.vws << static_cast(mols); + sds << mols.vws << static_cast(mols); return ds; } /** Extract from a binary datastream */ -template<> +template <> SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mols) { VersionID v = readHeader(ds, r_sres); @@ -141,7 +141,7 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mols if (v == 1) { SharedDataStream sds(ds); - sds >> mols.vws >> static_cast(mols); + sds >> mols.vws >> static_cast(mols); } else throw version_error(v, "1", r_sres, CODELOC); @@ -149,20 +149,20 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mols return ds; } /** Serialise to a binary datastream */ -template<> +template <> SIREMOL_EXPORT QDataStream &operator<<(QDataStream &ds, const SelectorM &mols) { writeHeader(ds, r_schn, 1); SharedDataStream sds(ds); - sds << mols.vws << static_cast(mols); + sds << mols.vws << static_cast(mols); return ds; } /** Extract from a binary datastream */ -template<> +template <> SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mols) { VersionID v = readHeader(ds, r_schn); @@ -170,7 +170,7 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mols) if (v == 1) { SharedDataStream sds(ds); - sds >> mols.vws >> static_cast(mols); + sds >> mols.vws >> static_cast(mols); } else throw version_error(v, "1", r_schn, CODELOC); @@ -178,20 +178,20 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mols) return ds; } /** Serialise to a binary datastream */ -template<> +template <> SIREMOL_EXPORT QDataStream &operator<<(QDataStream &ds, const SelectorM &mols) { writeHeader(ds, r_sseg, 1); SharedDataStream sds(ds); - sds << mols.vws << static_cast(mols); + sds << mols.vws << static_cast(mols); return ds; } /** Extract from a binary datastream */ -template<> +template <> SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mols) { VersionID v = readHeader(ds, r_sseg); @@ -199,7 +199,7 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mols if (v == 1) { SharedDataStream sds(ds); - sds >> mols.vws >> static_cast(mols); + sds >> mols.vws >> static_cast(mols); } else throw version_error(v, "1", r_sseg, CODELOC); @@ -207,20 +207,20 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mols return ds; } /** Serialise to a binary datastream */ -template<> +template <> SIREMOL_EXPORT QDataStream &operator<<(QDataStream &ds, const SelectorM &mols) { writeHeader(ds, r_scg, 1); SharedDataStream sds(ds); - sds << mols.vws << static_cast(mols); + sds << mols.vws << static_cast(mols); return ds; } /** Extract from a binary datastream */ -template<> +template <> SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mols) { VersionID v = readHeader(ds, r_scg); @@ -228,7 +228,7 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mol if (v == 1) { SharedDataStream sds(ds); - sds >> mols.vws >> static_cast(mols); + sds >> mols.vws >> static_cast(mols); } else throw version_error(v, "1", r_scg, CODELOC); @@ -236,17 +236,18 @@ SIREMOL_EXPORT QDataStream &operator>>(QDataStream &ds, SelectorM &mol return ds; } -SelectorMol::SelectorMol() : ConcreteProperty() -{} +SelectorMol::SelectorMol() : ConcreteProperty() +{ +} SelectorMol::SelectorMol(const MoleculeView &mol) - : ConcreteProperty() + : ConcreteProperty() { this->mols.append(mol.molecule()); } SelectorMol::SelectorMol(const Molecules &molecules) - : ConcreteProperty() + : ConcreteProperty() { if (not molecules.isEmpty()) { @@ -257,9 +258,9 @@ SelectorMol::SelectorMol(const Molecules &molecules) auto molnums = toList(molecules.molNums()); - //sort them, as this is also likely the order the molecules - //were read in from a file, and so more likely to be the - //order the user would expect + // sort them, as this is also likely the order the molecules + // were read in from a file, and so more likely to be the + // order the user would expect std::sort(molnums.begin(), molnums.end()); this->mols.reserve(molnums.count()); @@ -272,7 +273,7 @@ SelectorMol::SelectorMol(const Molecules &molecules) } SelectorMol::SelectorMol(const MoleculeGroup &molecules) - : ConcreteProperty() + : ConcreteProperty() { if (not molecules.isEmpty()) { @@ -287,7 +288,7 @@ SelectorMol::SelectorMol(const MoleculeGroup &molecules) } SelectorMol::SelectorMol(const MolGroupsBase &molecules) - : ConcreteProperty() + : ConcreteProperty() { if (not molecules.isEmpty()) { @@ -302,7 +303,7 @@ SelectorMol::SelectorMol(const MolGroupsBase &molecules) } SelectorMol::SelectorMol(const SelectResult &molecules) - : ConcreteProperty() + : ConcreteProperty() { if (not molecules.isEmpty()) { @@ -316,19 +317,21 @@ SelectorMol::SelectorMol(const SelectResult &molecules) } SelectorMol::SelectorMol(const SelectorMol &other) - : ConcreteProperty(), - mols(other.mols) -{} + : ConcreteProperty(), + mols(other.mols) +{ +} SelectorMol::~SelectorMol() -{} +{ +} -const char* SelectorMol::typeName() +const char *SelectorMol::typeName() { return QMetaType::typeName(qMetaTypeId()); } -SelectorMol& SelectorMol::operator=(const SelectorMol &other) +SelectorMol &SelectorMol::operator=(const SelectorMol &other) { if (this != &other) { @@ -417,6 +420,49 @@ bool SelectorMol::isSelector() const return true; } +/** Return the index of 'view' in this list of molecules. + * Returns an empty list if the view is not in this collection + */ +QList SelectorMol::find(const Molecule &view) const +{ + QList matches; + + for (int i = 0; i < mols.count(); ++i) + { + if (mols.at(i).isSameMolecule(view)) + { + matches.append(i); + break; + } + } + + return matches; +} + +/** Return the index of 'views' in this list of molecules. + * Returns an empty list if none of the views are in this collection + */ +QList SelectorMol::find(const SelectorMol &views) const +{ + QList matches; + + for (int i = 0; i < views.count(); ++i) + { + const auto &view = views[i]; + + for (int j = 0; j < mols.count(); ++j) + { + if (mols.at(j).isSameMolecule(view)) + { + matches.append(j); + break; + } + } + } + + return matches; +} + void SelectorMol::update(const Molecules &molecules) { // better to create a map from MolNum to index here @@ -483,7 +529,7 @@ bool SelectorMol::contains(const MolNum &molnum) const return false; } -Molecule SelectorMol::molecule(int i, const PropertyMap&) const +Molecule SelectorMol::molecule(int i, const PropertyMap &) const { return this->mols.at(Index(i).map(this->mols.count())); } @@ -494,8 +540,10 @@ Molecule SelectorMol::molecule(const QString &name, const PropertyMap &map) cons if (m.count() > 1) throw SireMol::duplicate_molecule(QObject::tr( - "More than one molecule matches %1. Number of matches is %2.") - .arg(name).arg(m.count()), CODELOC); + "More than one molecule matches %1. Number of matches is %2.") + .arg(name) + .arg(m.count()), + CODELOC); BOOST_ASSERT(m.count() != 0); @@ -508,8 +556,10 @@ Molecule SelectorMol::molecule(const MolIdx &molid, const PropertyMap &map) cons if (m.count() > 1) throw SireMol::duplicate_molecule(QObject::tr( - "More than one molecule matches %1. Number of matches is %2.") - .arg(molid.toString()).arg(m.count()), CODELOC); + "More than one molecule matches %1. Number of matches is %2.") + .arg(molid.toString()) + .arg(m.count()), + CODELOC); BOOST_ASSERT(m.count() != 0); @@ -522,8 +572,10 @@ Molecule SelectorMol::molecule(const MolName &molid, const PropertyMap &map) con if (m.count() > 1) throw SireMol::duplicate_molecule(QObject::tr( - "More than one molecule matches %1. Number of matches is %2.") - .arg(molid.toString()).arg(m.count()), CODELOC); + "More than one molecule matches %1. Number of matches is %2.") + .arg(molid.toString()) + .arg(m.count()), + CODELOC); BOOST_ASSERT(m.count() != 0); @@ -536,8 +588,10 @@ Molecule SelectorMol::molecule(const MolNum &molid, const PropertyMap &map) cons if (m.count() > 1) throw SireMol::duplicate_molecule(QObject::tr( - "More than one molecule matches %1. Number of matches is %2.") - .arg(molid.toString()).arg(m.count()), CODELOC); + "More than one molecule matches %1. Number of matches is %2.") + .arg(molid.toString()) + .arg(m.count()), + CODELOC); BOOST_ASSERT(m.count() != 0); @@ -550,8 +604,10 @@ Molecule SelectorMol::molecule(const MolID &molid, const PropertyMap &map) const if (m.count() > 1) throw SireMol::duplicate_molecule(QObject::tr( - "More than one molecule matches %1. Number of matches is %2.") - .arg(molid.toString()).arg(m.count()), CODELOC); + "More than one molecule matches %1. Number of matches is %2.") + .arg(molid.toString()) + .arg(m.count()), + CODELOC); BOOST_ASSERT(m.count() != 0); @@ -569,7 +625,7 @@ SelectorMol SelectorMol::molecules(int i, const PropertyMap &map) const } SelectorMol SelectorMol::molecules(const SireBase::Slice &slice, - const PropertyMap&) const + const PropertyMap &) const { SelectorMol m; @@ -582,7 +638,7 @@ SelectorMol SelectorMol::molecules(const SireBase::Slice &slice, } SelectorMol SelectorMol::molecules(const QList &idxs, - const PropertyMap&) const + const PropertyMap &) const { SelectorMol m; @@ -601,7 +657,7 @@ SelectorMol SelectorMol::molecules(const QString &name, { return this->molecules(MolName(name)); } - catch(const SireError::exception &e) + catch (const SireError::exception &e) { try { @@ -609,17 +665,19 @@ SelectorMol SelectorMol::molecules(const QString &name, if (ret.count() == 0) throw SireMol::missing_molecule(QObject::tr( - "No molecule matches '%1'").arg(name), CODELOC); + "No molecule matches '%1'") + .arg(name), + CODELOC); return ret; } - catch(...) + catch (...) { if (name.length() < 5) - //likely a name error + // likely a name error e.throwSelf(); else - //likely a syntax error + // likely a syntax error throw; } } @@ -634,7 +692,7 @@ SelectorMol SelectorMol::molecules(const MolIdx &molid, } SelectorMol SelectorMol::molecules(const MolName &molname, - const PropertyMap&) const + const PropertyMap &) const { SelectorMol m; @@ -648,14 +706,15 @@ SelectorMol SelectorMol::molecules(const MolName &molname, if (m.isEmpty()) throw SireMol::missing_molecule(QObject::tr( - "There is no molecule called %1 in this container.") - .arg(molname), CODELOC); + "There is no molecule called %1 in this container.") + .arg(molname), + CODELOC); return m; } SelectorMol SelectorMol::molecules(const MolNum &molnum, - const PropertyMap&) const + const PropertyMap &) const { SelectorMol m; @@ -671,8 +730,9 @@ SelectorMol SelectorMol::molecules(const MolNum &molnum, if (m.isEmpty()) throw SireMol::missing_molecule(QObject::tr( - "There is no molecule with number %1 in this container.") - .arg(molnum), CODELOC); + "There is no molecule with number %1 in this container.") + .arg(molnum), + CODELOC); return m; } @@ -690,13 +750,13 @@ MoleculeGroup SelectorMol::toMoleculeGroup() const } SelectorMol SelectorMol::molecules(const MolID &molid, - const PropertyMap&) const + const PropertyMap &) const { auto molnums = molid.map(this->toMoleculeGroup()); QHash m; - //QSet molnums_set(molnums.constBegin(), molnums.constEnd()); + // QSet molnums_set(molnums.constBegin(), molnums.constEnd()); QSet molnums_set = _list_to_set(molnums); for (const auto &mol : this->mols) @@ -723,7 +783,7 @@ SelectorMol SelectorMol::molecules(const MolID &molid, return ret; } -Atom SelectorMol::atom(int i, const PropertyMap&) const +Atom SelectorMol::atom(int i, const PropertyMap &) const { i = Index(i).map(this->nAtoms()); @@ -747,8 +807,10 @@ Atom SelectorMol::atom(const QString &name, if (atms.count() > 1) throw SireMol::duplicate_atom(QObject::tr( - "More than one atom matches the name '%1'. Number of matches is %2.") - .arg(name).arg(atms.count()), CODELOC); + "More than one atom matches the name '%1'. Number of matches is %2.") + .arg(name) + .arg(atms.count()), + CODELOC); BOOST_ASSERT(not atms.isEmpty()); @@ -761,15 +823,17 @@ Atom SelectorMol::atom(const AtomID &atomid, const PropertyMap &map) const if (atms.count() > 1) throw SireMol::duplicate_atom(QObject::tr( - "More than one atom matches '%1'. Number of matches is %2.") - .arg(atomid.toString()).arg(atms.count()), CODELOC); + "More than one atom matches '%1'. Number of matches is %2.") + .arg(atomid.toString()) + .arg(atms.count()), + CODELOC); BOOST_ASSERT(not atms.isEmpty()); return atms[0]; } -Residue SelectorMol::residue(int i, const PropertyMap&) const +Residue SelectorMol::residue(int i, const PropertyMap &) const { i = Index(i).map(this->nResidues()); @@ -793,8 +857,10 @@ Residue SelectorMol::residue(const QString &name, if (res.count() > 1) throw SireMol::duplicate_residue(QObject::tr( - "More than one residue matches the name '%1'. Number of matches is %2.") - .arg(name).arg(res.count()), CODELOC); + "More than one residue matches the name '%1'. Number of matches is %2.") + .arg(name) + .arg(res.count()), + CODELOC); BOOST_ASSERT(not res.isEmpty()); @@ -808,15 +874,17 @@ Residue SelectorMol::residue(const ResID &resid, if (res.count() > 1) throw SireMol::duplicate_residue(QObject::tr( - "More than one residue matches '%1'. Number of matches is %2.") - .arg(resid.toString()).arg(res.count()), CODELOC); + "More than one residue matches '%1'. Number of matches is %2.") + .arg(resid.toString()) + .arg(res.count()), + CODELOC); BOOST_ASSERT(not res.isEmpty()); return res[0]; } -Chain SelectorMol::chain(int i, const PropertyMap&) const +Chain SelectorMol::chain(int i, const PropertyMap &) const { i = Index(i).map(this->nChains()); @@ -840,8 +908,10 @@ Chain SelectorMol::chain(const QString &name, if (cs.count() > 1) throw SireMol::duplicate_chain(QObject::tr( - "More than one chain matches the name '%1'. Number of matches is %2.") - .arg(name).arg(cs.count()), CODELOC); + "More than one chain matches the name '%1'. Number of matches is %2.") + .arg(name) + .arg(cs.count()), + CODELOC); BOOST_ASSERT(not cs.isEmpty()); @@ -855,15 +925,17 @@ Chain SelectorMol::chain(const ChainID &chainid, if (cs.count() > 1) throw SireMol::duplicate_chain(QObject::tr( - "More than one chain matches '%1'. Number of matches is %2.") - .arg(chainid.toString()).arg(cs.count()), CODELOC); + "More than one chain matches '%1'. Number of matches is %2.") + .arg(chainid.toString()) + .arg(cs.count()), + CODELOC); BOOST_ASSERT(not cs.isEmpty()); return cs[0]; } -Segment SelectorMol::segment(int i, const PropertyMap&) const +Segment SelectorMol::segment(int i, const PropertyMap &) const { i = Index(i).map(this->nSegments()); @@ -887,8 +959,10 @@ Segment SelectorMol::segment(const QString &name, if (segs.count() > 1) throw SireMol::duplicate_segment(QObject::tr( - "More than one segment matches the name '%1'. Number of matches is %2.") - .arg(name).arg(segs.count()), CODELOC); + "More than one segment matches the name '%1'. Number of matches is %2.") + .arg(name) + .arg(segs.count()), + CODELOC); BOOST_ASSERT(not segs.isEmpty()); @@ -902,15 +976,17 @@ Segment SelectorMol::segment(const SegID &segid, if (segs.count() > 1) throw SireMol::duplicate_segment(QObject::tr( - "More than one segment matches '%1'. Number of matches is %2.") - .arg(segid.toString()).arg(segs.count()), CODELOC); + "More than one segment matches '%1'. Number of matches is %2.") + .arg(segid.toString()) + .arg(segs.count()), + CODELOC); BOOST_ASSERT(not segs.isEmpty()); return segs[0]; } -CutGroup SelectorMol::cutGroup(int i, const PropertyMap&) const +CutGroup SelectorMol::cutGroup(int i, const PropertyMap &) const { i = Index(i).map(this->nCutGroups()); @@ -934,8 +1010,10 @@ CutGroup SelectorMol::cutGroup(const QString &name, if (cgs.count() > 1) throw SireMol::duplicate_cutgroup(QObject::tr( - "More than one CutGroup matches the name '%1'. Number of matches is %2.") - .arg(name).arg(cgs.count()), CODELOC); + "More than one CutGroup matches the name '%1'. Number of matches is %2.") + .arg(name) + .arg(cgs.count()), + CODELOC); BOOST_ASSERT(not cgs.isEmpty()); @@ -949,8 +1027,10 @@ CutGroup SelectorMol::cutGroup(const CGID &cgid, if (cgs.count() > 1) throw SireMol::duplicate_cutgroup(QObject::tr( - "More than one CutGroup matches '%1'. Number of matches is %2.") - .arg(cgid.toString()).arg(cgs.count()), CODELOC); + "More than one CutGroup matches '%1'. Number of matches is %2.") + .arg(cgid.toString()) + .arg(cgs.count()), + CODELOC); BOOST_ASSERT(not cgs.isEmpty()); @@ -968,13 +1048,13 @@ SelectorM SelectorMol::atoms(int i, const PropertyMap &map) const } SelectorM SelectorMol::atoms(const SireBase::Slice &slice, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, slice); } SelectorM SelectorMol::atoms(const QList &idxs, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, idxs); } @@ -986,7 +1066,7 @@ SelectorM SelectorMol::atoms(const QString &name, } SelectorM SelectorMol::atoms(const AtomID &atomid, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, atomid); } @@ -1002,13 +1082,13 @@ SelectorM SelectorMol::residues(int i, const PropertyMap &map) const } SelectorM SelectorMol::residues(const SireBase::Slice &slice, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, slice); } SelectorM SelectorMol::residues(const QList &idxs, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, idxs); } @@ -1020,7 +1100,7 @@ SelectorM SelectorMol::residues(const QString &name, } SelectorM SelectorMol::residues(const ResID &resid, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, resid); } @@ -1037,13 +1117,13 @@ SelectorM SelectorMol::chains(int i, } SelectorM SelectorMol::chains(const SireBase::Slice &slice, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, slice); } SelectorM SelectorMol::chains(const QList &idxs, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, idxs); } @@ -1055,7 +1135,7 @@ SelectorM SelectorMol::chains(const QString &name, } SelectorM SelectorMol::chains(const ChainID &chainid, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, chainid); } @@ -1072,13 +1152,13 @@ SelectorM SelectorMol::segments(int i, } SelectorM SelectorMol::segments(const SireBase::Slice &slice, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, slice); } SelectorM SelectorMol::segments(const QList &idxs, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, idxs); } @@ -1090,7 +1170,7 @@ SelectorM SelectorMol::segments(const QString &name, } SelectorM SelectorMol::segments(const SegID &segid, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, segid); } @@ -1107,13 +1187,13 @@ SelectorM SelectorMol::cutGroups(int i, } SelectorM SelectorMol::cutGroups(const SireBase::Slice &slice, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, slice); } SelectorM SelectorMol::cutGroups(const QList &idxs, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, idxs); } @@ -1125,7 +1205,7 @@ SelectorM SelectorMol::cutGroups(const QString &name, } SelectorM SelectorMol::cutGroups(const CGID &cgid, - const PropertyMap&) const + const PropertyMap &) const { return SelectorM(*this, cgid); } @@ -1159,7 +1239,7 @@ QList SelectorMol::indexes() const QList idxs; idxs.reserve(this->mols.count()); - for (int i=0; imols.count(); ++i) + for (int i = 0; i < this->mols.count(); ++i) { idxs.append(MolIdx(i)); } @@ -1353,35 +1433,32 @@ QString SelectorMol::toString() const if (n <= 10) { - for (int i=0; imols[i].toString())); + parts.append(QObject::tr("%1: %2").arg(i).arg(this->mols[i].toString())); } } else { - for (int i=0; i<5; ++i) + for (int i = 0; i < 5; ++i) { - parts.append(QObject::tr("%1: %2").arg(i) - .arg(this->mols[i].toString())); + parts.append(QObject::tr("%1: %2").arg(i).arg(this->mols[i].toString())); } parts.append("..."); - for (int i=n-5; imols[i].toString())); + parts.append(QObject::tr("%1: %2").arg(i).arg(this->mols[i].toString())); } } return QObject::tr("SelectorMol( size=%1\n%2\n)") - .arg(n).arg(parts.join("\n")); + .arg(n) + .arg(parts.join("\n")); } } - namespace SireMol { template class SelectorM; diff --git a/corelib/src/libs/SireMol/selectormol.h b/corelib/src/libs/SireMol/selectormol.h index 757d66dfb..30fff4985 100644 --- a/corelib/src/libs/SireMol/selectormol.h +++ b/corelib/src/libs/SireMol/selectormol.h @@ -47,7 +47,7 @@ namespace SireMol class SelectorMol; class EvaluatorM; - template + template class SelectorM; class Molecules; @@ -66,263 +66,266 @@ namespace SireMol class MolIdx; } -SIREMOL_EXPORT QDataStream& operator<<(QDataStream&, const SireMol::SelectorMol&); -SIREMOL_EXPORT QDataStream& operator>>(QDataStream&, SireMol::SelectorMol&); +SIREMOL_EXPORT QDataStream &operator<<(QDataStream &, const SireMol::SelectorMol &); +SIREMOL_EXPORT QDataStream &operator>>(QDataStream &, SireMol::SelectorMol &); namespace SireMol { -/** This class provides a Selector-type interface to a - collection of molecules. -*/ -class SIREMOL_EXPORT SelectorMol - : public SireBase::ConcreteProperty -{ + /** This class provides a Selector-type interface to a + collection of molecules. + */ + class SIREMOL_EXPORT SelectorMol + : public SireBase::ConcreteProperty + { -friend SIREMOL_EXPORT QDataStream& ::operator<<(QDataStream&, const SelectorMol&); -friend SIREMOL_EXPORT QDataStream& ::operator>>(QDataStream&, SelectorMol&); + friend SIREMOL_EXPORT QDataStream & ::operator<<(QDataStream &, const SelectorMol &); + friend SIREMOL_EXPORT QDataStream & ::operator>>(QDataStream &, SelectorMol &); -public: - typedef QList::const_iterator const_iterator; - typedef QList::const_iterator iterator; + public: + typedef QList::const_iterator const_iterator; + typedef QList::const_iterator iterator; - SelectorMol(); - SelectorMol(const MoleculeView &mol); - SelectorMol(const Molecules &mols); - SelectorMol(const MoleculeGroup &mols); - SelectorMol(const MolGroupsBase &mols); - SelectorMol(const SelectResult &mols); + SelectorMol(); + SelectorMol(const MoleculeView &mol); + SelectorMol(const Molecules &mols); + SelectorMol(const MoleculeGroup &mols); + SelectorMol(const MolGroupsBase &mols); + SelectorMol(const SelectResult &mols); - template - SelectorMol(const SelectorM &other); - template - SelectorMol(const SelectorM &other, const QString &name, - const SireBase::PropertyMap &map = SireBase::PropertyMap()); - template - SelectorMol(const SelectorM &other, const SireBase::Slice &slice); - template - SelectorMol(const SelectorM &other, const QList &idxs); - template - SelectorMol(const SelectorM &other, const MolID &molid); + template + SelectorMol(const SelectorM &other); + template + SelectorMol(const SelectorM &other, const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()); + template + SelectorMol(const SelectorM &other, const SireBase::Slice &slice); + template + SelectorMol(const SelectorM &other, const QList &idxs); + template + SelectorMol(const SelectorM &other, const MolID &molid); - SelectorMol(const SelectorMol &other); + SelectorMol(const SelectorMol &other); - virtual ~SelectorMol(); + virtual ~SelectorMol(); - static const char* typeName(); + static const char *typeName(); - virtual const char* what() const - { - return SelectorMol::typeName(); - } + virtual const char *what() const + { + return SelectorMol::typeName(); + } - virtual SelectorMol* clone() const - { - return new SelectorMol(*this); - } + virtual SelectorMol *clone() const + { + return new SelectorMol(*this); + } - SelectorMol& operator=(const SelectorMol &other); + SelectorMol &operator=(const SelectorMol &other); - bool operator==(const SelectorMol &other) const; - bool operator!=(const SelectorMol &other) const; + bool operator==(const SelectorMol &other) const; + bool operator!=(const SelectorMol &other) const; - Molecule operator[](int i) const; - SelectorMol operator[](const SireBase::Slice &slice) const; - SelectorMol operator[](const QList &idxs) const; - Molecule operator[](const QString &name) const; - Molecule operator[](const MolIdx &molidx) const; - Molecule operator[](const MolName &molname) const; - Molecule operator[](const MolNum &molnum) const; - Molecule operator[](const MolID &molid) const; + Molecule operator[](int i) const; + SelectorMol operator[](const SireBase::Slice &slice) const; + SelectorMol operator[](const QList &idxs) const; + Molecule operator[](const QString &name) const; + Molecule operator[](const MolIdx &molidx) const; + Molecule operator[](const MolName &molname) const; + Molecule operator[](const MolNum &molnum) const; + Molecule operator[](const MolID &molid) const; - QList toList() const; - Molecules toMolecules() const; + QList toList() const; + Molecules toMolecules() const; - int count() const; - int size() const; + int count() const; + int size() const; - void update(const Molecules &molecules); + void update(const Molecules &molecules); - EvaluatorM evaluate() const; + EvaluatorM evaluate() const; - MoleculeGroup toMoleculeGroup() const; - SelectResult toSelectResult() const; + MoleculeGroup toMoleculeGroup() const; + SelectResult toSelectResult() const; - bool isSelector() const; + bool isSelector() const; - Molecule molecule(int i, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - Molecule molecule(const QString &name, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - Molecule molecule(const MolIdx &molidx, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - Molecule molecule(const MolName &molname, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - Molecule molecule(const MolNum &molnum, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - Molecule molecule(const MolID &molid, - const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + QList find(const Molecule &view) const; + QList find(const SelectorMol &views) const; - SelectorMol molecules() const; - SelectorMol molecules(int i, + Molecule molecule(int i, const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - SelectorMol molecules(const SireBase::Slice &slice, + Molecule molecule(const QString &name, const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - SelectorMol molecules(const QList &idxs, + Molecule molecule(const MolIdx &molidx, const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - SelectorMol molecules(const QString &name, + Molecule molecule(const MolName &molname, const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - SelectorMol molecules(const MolIdx &molidx, + Molecule molecule(const MolNum &molnum, const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - SelectorMol molecules(const MolName &molname, + Molecule molecule(const MolID &molid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SelectorMol molecules() const; + SelectorMol molecules(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorMol molecules(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorMol molecules(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorMol molecules(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorMol molecules(const MolIdx &molidx, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorMol molecules(const MolName &molname, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorMol molecules(const MolNum &molnum, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorMol molecules(const MolID &molid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + bool contains(const MolNum &molnum) const; + + Atom atom(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Atom atom(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Atom atom(const AtomID &atomid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + Residue residue(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Residue residue(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Residue residue(const ResID &resid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + Chain chain(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Chain chain(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Chain chain(const ChainID &chainid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + Segment segment(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Segment segment(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + Segment segment(const SegID &segid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + CutGroup cutGroup(int i, const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - SelectorMol molecules(const MolNum &molnum, + CutGroup cutGroup(const QString &name, const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - SelectorMol molecules(const MolID &molid, + CutGroup cutGroup(const CGID &cgid, const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; - bool contains(const MolNum &molnum) const; - - Atom atom(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - Atom atom(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - Atom atom(const AtomID &atomid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - Residue residue(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - Residue residue(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - Residue residue(const ResID &resid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - Chain chain(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - Chain chain(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - Chain chain(const ChainID &chainid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - Segment segment(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - Segment segment(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - Segment segment(const SegID &segid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - CutGroup cutGroup(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - CutGroup cutGroup(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - CutGroup cutGroup(const CGID &cgid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SelectorM atoms() const; - SelectorM atoms(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM atoms(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM atoms(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM atoms(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM atoms(const AtomID &atomid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SelectorM residues() const; - SelectorM residues(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM residues(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM residues(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM residues(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM residues(const ResID &resid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SelectorM chains() const; - SelectorM chains(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM chains(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM chains(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM chains(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM chains(const ChainID &chainid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SelectorM segments() const; - SelectorM segments(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM segments(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM segments(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM segments(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM segments(const SegID &segid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SelectorM cutGroups() const; - SelectorM cutGroups(int i, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM cutGroups(const SireBase::Slice &slice, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM cutGroups(const QList &idxs, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM cutGroups(const QString &name, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - SelectorM cutGroups(const CGID &cgid, - const SireBase::PropertyMap &map=SireBase::PropertyMap()) const; - - SelectResult search(const QString &search_string) const; - SelectResult search(const QString &search_string, - const SireBase::PropertyMap &map) const; - - QVector molNums() const; - - QList IDs() const; - QList indexes() const; - QList numbers() const; - QList names() const; - - int nAtoms() const; - int nResidues() const; - int nChains() const; - int nSegments() const; - int nCutGroups() const; - int nMolecules() const; - - bool isEmpty() const; - - int nFrames() const; - int nFrames(const SireBase::PropertyMap &map) const; - - void loadFrame(int frame); - void saveFrame(int frame); - void saveFrame(); - void deleteFrame(int frame); - - void loadFrame(int frame, const SireBase::PropertyMap &map); - void saveFrame(int frame, const SireBase::PropertyMap &map); - void saveFrame(const SireBase::PropertyMap &map); - void deleteFrame(int frame, const SireBase::PropertyMap &map); - - const_iterator begin() const; - const_iterator end() const; - - const_iterator constBegin() const; - const_iterator constEnd() const; - - virtual QString toString() const; - -protected: - /** The actual list of molecules */ - QList mols; -}; + SelectorM atoms() const; + SelectorM atoms(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM atoms(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM atoms(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM atoms(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM atoms(const AtomID &atomid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SelectorM residues() const; + SelectorM residues(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM residues(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM residues(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM residues(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM residues(const ResID &resid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SelectorM chains() const; + SelectorM chains(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM chains(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM chains(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM chains(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM chains(const ChainID &chainid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SelectorM segments() const; + SelectorM segments(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM segments(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM segments(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM segments(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM segments(const SegID &segid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SelectorM cutGroups() const; + SelectorM cutGroups(int i, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM cutGroups(const SireBase::Slice &slice, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM cutGroups(const QList &idxs, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM cutGroups(const QString &name, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + SelectorM cutGroups(const CGID &cgid, + const SireBase::PropertyMap &map = SireBase::PropertyMap()) const; + + SelectResult search(const QString &search_string) const; + SelectResult search(const QString &search_string, + const SireBase::PropertyMap &map) const; + + QVector molNums() const; + + QList IDs() const; + QList indexes() const; + QList numbers() const; + QList names() const; + + int nAtoms() const; + int nResidues() const; + int nChains() const; + int nSegments() const; + int nCutGroups() const; + int nMolecules() const; + + bool isEmpty() const; + + int nFrames() const; + int nFrames(const SireBase::PropertyMap &map) const; + + void loadFrame(int frame); + void saveFrame(int frame); + void saveFrame(); + void deleteFrame(int frame); + + void loadFrame(int frame, const SireBase::PropertyMap &map); + void saveFrame(int frame, const SireBase::PropertyMap &map); + void saveFrame(const SireBase::PropertyMap &map); + void deleteFrame(int frame, const SireBase::PropertyMap &map); + + const_iterator begin() const; + const_iterator end() const; + + const_iterator constBegin() const; + const_iterator constEnd() const; + + virtual QString toString() const; + + protected: + /** The actual list of molecules */ + QList mols; + }; } @@ -335,11 +338,11 @@ Q_DECLARE_METATYPE(SireMol::SelectorM); SIRE_EXPOSE_CLASS(SireMol::SelectorMol) -SIRE_EXPOSE_ALIAS( SireMol::SelectorM, SireMol::SelectorM_Atom_ ) -SIRE_EXPOSE_ALIAS( SireMol::SelectorM, SireMol::SelectorM_Residue_ ) -SIRE_EXPOSE_ALIAS( SireMol::SelectorM, SireMol::SelectorM_Chain_ ) -SIRE_EXPOSE_ALIAS( SireMol::SelectorM, SireMol::SelectorM_Segment_ ) -SIRE_EXPOSE_ALIAS( SireMol::SelectorM, SireMol::SelectorM_CutGroup_ ) +SIRE_EXPOSE_ALIAS(SireMol::SelectorM, SireMol::SelectorM_Atom_) +SIRE_EXPOSE_ALIAS(SireMol::SelectorM, SireMol::SelectorM_Residue_) +SIRE_EXPOSE_ALIAS(SireMol::SelectorM, SireMol::SelectorM_Chain_) +SIRE_EXPOSE_ALIAS(SireMol::SelectorM, SireMol::SelectorM_Segment_) +SIRE_EXPOSE_ALIAS(SireMol::SelectorM, SireMol::SelectorM_CutGroup_) // include this here so that SelectorM is always instantiatable if // SelectorMol has been included @@ -350,61 +353,61 @@ SIRE_EXPOSE_ALIAS( SireMol::SelectorM, SireMol::SelectorM_Cut namespace SireMol { -template -SIRE_OUTOFLINE_TEMPLATE -SelectorMol::SelectorMol(const SelectorM &other) - : SireBase::ConcreteProperty() -{ - if (not other.isEmpty()) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorMol::SelectorMol(const SelectorM &other) + : SireBase::ConcreteProperty() { - this->mols.reserve(other.nMolecules()); - - for (int i=0; imols.append(other.molecule(i)); + this->mols.reserve(other.nMolecules()); + + for (int i = 0; i < other.nMolecules(); ++i) + { + this->mols.append(other.molecule(i)); + } } } -} -template -SIRE_OUTOFLINE_TEMPLATE -SelectorMol::SelectorMol(const SelectorM &other, const QString &name, - const PropertyMap &map) - : SireBase::ConcreteProperty() -{ - this->operator=(SelectorMol(other).molecules(name, map)); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorMol::SelectorMol(const SelectorM &other, const QString &name, + const PropertyMap &map) + : SireBase::ConcreteProperty() + { + this->operator=(SelectorMol(other).molecules(name, map)); + } -template -SIRE_OUTOFLINE_TEMPLATE -SelectorMol::SelectorMol(const SelectorM &other, const SireBase::Slice &slice) - : SireBase::ConcreteProperty() -{ - for (auto it = slice.begin(other.nMolecules()); - not it.atEnd(); it.next()) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorMol::SelectorMol(const SelectorM &other, const SireBase::Slice &slice) + : SireBase::ConcreteProperty() { - this->mols.append(other.molecule(it.value())); + for (auto it = slice.begin(other.nMolecules()); + not it.atEnd(); it.next()) + { + this->mols.append(other.molecule(it.value())); + } } -} -template -SIRE_OUTOFLINE_TEMPLATE -SelectorMol::SelectorMol(const SelectorM &other, const QList &idxs) - : SireBase::ConcreteProperty() -{ - for (const auto &idx : idxs) + template + SIRE_OUTOFLINE_TEMPLATE + SelectorMol::SelectorMol(const SelectorM &other, const QList &idxs) + : SireBase::ConcreteProperty() { - this->mols.append(other.molecule(idx)); + for (const auto &idx : idxs) + { + this->mols.append(other.molecule(idx)); + } } -} -template -SIRE_OUTOFLINE_TEMPLATE -SelectorMol::SelectorMol(const SelectorM &other, const MolID &molid) - : SireBase::ConcreteProperty() -{ - this->operator=(other.molecules().molecules(molid)); -} + template + SIRE_OUTOFLINE_TEMPLATE + SelectorMol::SelectorMol(const SelectorM &other, const MolID &molid) + : SireBase::ConcreteProperty() + { + this->operator=(other.molecules().molecules(molid)); + } } // end of namespace SireMol @@ -420,7 +423,7 @@ template class SireMol::SelectorM; template class SireMol::SelectorM; template class SireMol::SelectorM; -#endif //SIRE_INSTANTIATE_TEMPLATES +#endif // SIRE_INSTANTIATE_TEMPLATES SIRE_END_HEADER diff --git a/corelib/src/libs/SireMove/ensemble.cpp b/corelib/src/libs/SireMove/ensemble.cpp index a6d6f0a59..d77020b74 100644 --- a/corelib/src/libs/SireMove/ensemble.cpp +++ b/corelib/src/libs/SireMove/ensemble.cpp @@ -49,10 +49,10 @@ using namespace SireMove::detail; static const RegisterMetaType r_ensemble; -template -static QDataStream& operator<<(QDataStream &ds, const CharArray &array) +template +static QDataStream &operator<<(QDataStream &ds, const CharArray &array) { - for (int i=0; i::count(); ++i) + for (int i = 0; i < CharArray::count(); ++i) { ds << array[i]; } @@ -60,10 +60,10 @@ static QDataStream& operator<<(QDataStream &ds, const CharArray &array) return ds; } -template -static QDataStream& operator>>(QDataStream &ds, CharArray &array) +template +static QDataStream &operator>>(QDataStream &ds, CharArray &array) { - for (int i=0; i::count(); ++i) + for (int i = 0; i < CharArray::count(); ++i) { ds >> array[i]; } @@ -80,7 +80,7 @@ QDataStream &operator<<(QDataStream &ds, const Ensemble &ensemble) << double(ensemble.ensemble_pressure) << double(ensemble.ensemble_fugacity) << ensemble.ensemble_state - << static_cast(ensemble); + << static_cast(ensemble); return ds; } @@ -94,30 +94,28 @@ QDataStream &operator>>(QDataStream &ds, Ensemble &ensemble) { double temp, press, fug; - ds >> temp >> press >> fug - >> ensemble.ensemble_state - >> static_cast(ensemble); + ds >> temp >> press >> fug >> ensemble.ensemble_state >> static_cast(ensemble); ensemble.ensemble_temperature = Temperature(temp); ensemble.ensemble_pressure = Pressure(press); ensemble.ensemble_fugacity = Pressure(fug); } else - throw version_error( v, "1", r_ensemble, CODELOC ); + throw version_error(v, "1", r_ensemble, CODELOC); return ds; } static const quint8 UNKNOWN = 0; // unknown state -static const quint8 N = 4; // constant number of particles -static const quint8 Mu = 16; // constant chemical potential +static const quint8 N = 4; // constant number of particles +static const quint8 Mu = 16; // constant chemical potential -static const quint8 V = 4; // constant volume -static const quint8 P = 16; // constant pressure +static const quint8 V = 4; // constant volume +static const quint8 P = 16; // constant pressure -static const quint8 E = 4; // constant total energy -static const quint8 T = 16; // constant temperature +static const quint8 E = 4; // constant total energy +static const quint8 T = 16; // constant temperature /** Return the description for the passed state parameters */ static CharArray getDescription(quint8 n, quint8 v, quint8 t) @@ -132,15 +130,15 @@ static CharArray getDescription(quint8 n, quint8 v, quint8 t) } /** Return the merged version of the passed two states */ -template +template static CharArray merge(const CharArray &des0, const CharArray &des1) { CharArray merged; - for (int i=0; i::count(); ++i) + for (int i = 0; i < CharArray::count(); ++i) { - merged[i] = qMax( des0[i], des1[i] ); + merged[i] = qMax(des0[i], des1[i]); } return merged; @@ -148,26 +146,28 @@ static CharArray merge(const CharArray &des0, /** Construct an NVE ensemble */ Ensemble::Ensemble() - : ensemble_temperature(0), ensemble_pressure(0), - ensemble_fugacity(0) + : ensemble_temperature(0), ensemble_pressure(0), + ensemble_fugacity(0) { - ensemble_state = getDescription( N, V, E ); + ensemble_state = getDescription(N, V, E); } /** Copy constructor */ Ensemble::Ensemble(const Ensemble &other) - : ensemble_temperature(other.ensemble_temperature), - ensemble_pressure(other.ensemble_pressure), - ensemble_fugacity(other.ensemble_fugacity), - ensemble_state(other.ensemble_state) -{} + : ensemble_temperature(other.ensemble_temperature), + ensemble_pressure(other.ensemble_pressure), + ensemble_fugacity(other.ensemble_fugacity), + ensemble_state(other.ensemble_state) +{ +} /** Destructor */ Ensemble::~Ensemble() -{} +{ +} /** Copy assignment operator */ -Ensemble& Ensemble::operator=(const Ensemble &other) +Ensemble &Ensemble::operator=(const Ensemble &other) { if (this != &other) { @@ -240,25 +240,25 @@ bool Ensemble::isConstantChemicalPotential() const /** Return whether or not this is the NVE ensemble */ bool Ensemble::isNVE() const { - return ensemble_state == getDescription( N, V, E ); + return ensemble_state == getDescription(N, V, E); } /** Return whether or not this is the NVT ensemble */ bool Ensemble::isNVT() const { - return ensemble_state == getDescription( N, V, T ); + return ensemble_state == getDescription(N, V, T); } /** Return whether or not this is the NPT ensemble */ bool Ensemble::isNPT() const { - return ensemble_state == getDescription( N, P, T ); + return ensemble_state == getDescription(N, P, T); } /** Return whether or not this is the MuVT ensemble */ bool Ensemble::isMuVT() const { - return ensemble_state == getDescription( Mu, V, T ); + return ensemble_state == getDescription(Mu, V, T); } /** Return whether or not this is the microcanonical (NVE) ensemble */ @@ -292,41 +292,41 @@ QString Ensemble::shortHand() const switch (ensemble_state[0]) { - case N: - shorthand[0] = 'N'; - break; - case Mu: - shorthand[0] = 'M'; // #warning Need greek Mu character - break; - default: - shorthand[0] = '?'; - break; + case N: + shorthand[0] = 'N'; + break; + case Mu: + shorthand[0] = 'M'; // #warning Need greek Mu character + break; + default: + shorthand[0] = '?'; + break; } switch (ensemble_state[1]) { - case V: - shorthand[1] = 'V'; - break; - case P: - shorthand[1] = 'P'; - break; - default: - shorthand[1] = '?'; - break; + case V: + shorthand[1] = 'V'; + break; + case P: + shorthand[1] = 'P'; + break; + default: + shorthand[1] = '?'; + break; } switch (ensemble_state[2]) { - case E: - shorthand[2] = 'E'; - break; - case T: - shorthand[2] = 'T'; - break; - default: - shorthand[2] = '?'; - break; + case E: + shorthand[2] = 'E'; + break; + case T: + shorthand[2] = 'T'; + break; + default: + shorthand[2] = '?'; + break; } return shorthand; @@ -358,20 +358,20 @@ QString Ensemble::toString() const if (this->isConstantChemicalPotential()) { - parts.append( QObject::tr("chemical potential = %1 kcal mol-1") - .arg( this->chemicalPotential().to(kcal_per_mol) ) ); + parts.append(QObject::tr("chemical potential = %1 kcal mol-1") + .arg(this->chemicalPotential().to(kcal_per_mol))); } if (this->isConstantPressure()) { - parts.append( QObject::tr("pressure = %1 atm") - .arg( this->pressure().to(atm) ) ); + parts.append(QObject::tr("pressure = %1 atm") + .arg(this->pressure().to(atm))); } if (this->isConstantTemperature()) { - parts.append( QObject::tr("temperature = %1 C") - .arg( this->temperature().to(Celsius()) ) ); + parts.append(QObject::tr("temperature = %1 C") + .arg(this->temperature().to(Celsius()))); } if (parts.isEmpty()) @@ -379,7 +379,7 @@ QString Ensemble::toString() const else return QString("%1 { %2 }") - .arg(this->name(), Sire::toString(parts)); + .arg(this->name(), Sire::toString(parts)); } /** Return the temperature of this ensemble @@ -389,9 +389,10 @@ QString Ensemble::toString() const Temperature Ensemble::temperature() const { if (not this->isConstantTemperature()) - throw SireError::incompatible_error( QObject::tr( - "The %1 ensemble does not have a constant temperature.") - .arg(this->shortHand()), CODELOC ); + throw SireError::incompatible_error(QObject::tr( + "The %1 ensemble does not have a constant temperature.") + .arg(this->shortHand()), + CODELOC); return ensemble_temperature; } @@ -403,9 +404,10 @@ Temperature Ensemble::temperature() const Pressure Ensemble::pressure() const { if (not this->isConstantPressure()) - throw SireError::incompatible_error( QObject::tr( - "The %1 ensemble does not have a constant pressure.") - .arg(this->shortHand()), CODELOC ); + throw SireError::incompatible_error(QObject::tr( + "The %1 ensemble does not have a constant pressure.") + .arg(this->shortHand()), + CODELOC); return ensemble_pressure; } @@ -417,9 +419,10 @@ Pressure Ensemble::pressure() const Pressure Ensemble::fugacity() const { if (not this->isConstantFugacity()) - throw SireError::incompatible_error( QObject::tr( - "The %1 ensemble does not have a constant fugacity.") - .arg(this->shortHand()), CODELOC ); + throw SireError::incompatible_error(QObject::tr( + "The %1 ensemble does not have a constant fugacity.") + .arg(this->shortHand()), + CODELOC); return ensemble_fugacity; } @@ -431,9 +434,10 @@ Pressure Ensemble::fugacity() const MolarEnergy Ensemble::chemicalPotential() const { if (not this->isConstantChemicalPotential()) - throw SireError::incompatible_error( QObject::tr( - "The %1 ensemble does not have a constant chemical potential.") - .arg(this->shortHand()), CODELOC ); + throw SireError::incompatible_error(QObject::tr( + "The %1 ensemble does not have a constant chemical potential.") + .arg(this->shortHand()), + CODELOC); // mu = mu_0 + RT ln ( f / P_0 ) // @@ -443,8 +447,7 @@ MolarEnergy Ensemble::chemicalPotential() const // where P_0 is 1 bar (standard state) // we will actually return mu - mu_0 == RT ln (f / P_0 ) - return MolarEnergy( gasr * ensemble_temperature.value() - * std::log( ensemble_fugacity / 1.0*bar ) ); + return MolarEnergy(gasr * ensemble_temperature.value() * std::log(ensemble_fugacity / 1.0 * bar)); } /** Merge the two ensembles 'e0' and 'e1' together. This tries to find an ensemble @@ -570,8 +573,8 @@ Ensemble Ensemble::MuVT(const Temperature &temperature, // we will actually use mu - mu_0 == RT ln (f / P_0 ) // so chemical potential = mu - mu_0 - return Ensemble::MuVT( temperature, - std::exp( chemical_potential / (gasr*temperature) ) * bar ); + return Ensemble::MuVT(temperature, + std::exp(chemical_potential / (gasr.value() * temperature)) * bar); } /** Syntactic sugar to return the NVE ensemble */ @@ -607,12 +610,12 @@ Ensemble Ensemble::grandCanonical(const Temperature &temperature, return Ensemble::MuVT(temperature, chemical_potential); } -const char* Ensemble::typeName() +const char *Ensemble::typeName() { - return QMetaType::typeName( qMetaTypeId() ); + return QMetaType::typeName(qMetaTypeId()); } -Ensemble* Ensemble::clone() const +Ensemble *Ensemble::clone() const { return new Ensemble(*this); } diff --git a/corelib/src/libs/SireMove/moleculardynamics.cpp b/corelib/src/libs/SireMove/moleculardynamics.cpp index fe9c1b390..7b59afad1 100644 --- a/corelib/src/libs/SireMove/moleculardynamics.cpp +++ b/corelib/src/libs/SireMove/moleculardynamics.cpp @@ -53,7 +53,7 @@ static const RegisterMetaType r_moldyn; /** Serialise to a binary datastream */ QDataStream &operator<<(QDataStream &ds, - const MolecularDynamics &moldyn) + const MolecularDynamics &moldyn) { writeHeader(ds, r_moldyn, 1); @@ -61,14 +61,14 @@ QDataStream &operator<<(QDataStream &ds, sds << moldyn.intgrator << moldyn.wspace << moldyn.timestep << moldyn.num_moves << moldyn.total_time - << static_cast(moldyn); + << static_cast(moldyn); return ds; } /** Extract from a binary datastream */ QDataStream &operator>>(QDataStream &ds, - MolecularDynamics &moldyn) + MolecularDynamics &moldyn) { VersionID v = readHeader(ds, r_moldyn); @@ -76,10 +76,7 @@ QDataStream &operator>>(QDataStream &ds, { SharedDataStream sds(ds); - sds >> moldyn.intgrator >> moldyn.wspace >> moldyn.timestep - >> moldyn.num_moves >> moldyn.total_time - >> static_cast(moldyn); - + sds >> moldyn.intgrator >> moldyn.wspace >> moldyn.timestep >> moldyn.num_moves >> moldyn.total_time >> static_cast(moldyn); } else throw version_error(v, "1", r_moldyn, CODELOC); @@ -89,25 +86,25 @@ QDataStream &operator>>(QDataStream &ds, /** Constructor */ MolecularDynamics::MolecularDynamics(const PropertyMap &map) - : ConcreteProperty(map), - intgrator( Integrator::null() ), - wspace( IntegratorWorkspace::null() ), - timestep(1*femtosecond), - num_moves(0), total_time(0) + : ConcreteProperty(map), + intgrator(Integrator::null()), + wspace(IntegratorWorkspace::null()), + timestep(1 * femtosecond), + num_moves(0), total_time(0) { - Dynamics::setEnsemble( Ensemble::NVE() ); + Dynamics::setEnsemble(Ensemble::NVE()); } /** Construct to perform moves on the molecules in the group 'molgroup'. This defaults to an all-atom velocity-verlet integrator */ MolecularDynamics::MolecularDynamics(const MoleculeGroup &moleculegroup, const PropertyMap &map) - : ConcreteProperty(map), - intgrator( VelocityVerlet() ), timestep(1*femtosecond), - num_moves(0), total_time(0) + : ConcreteProperty(map), + intgrator(VelocityVerlet()), timestep(1 * femtosecond), + num_moves(0), total_time(0) { wspace = intgrator.read().createWorkspace(moleculegroup, map); - Dynamics::setEnsemble( intgrator.read().ensemble() ); + Dynamics::setEnsemble(intgrator.read().ensemble()); } /** Construct a move for the passed molecule group, integrated @@ -115,24 +112,24 @@ MolecularDynamics::MolecularDynamics(const MoleculeGroup &moleculegroup, MolecularDynamics::MolecularDynamics(const MoleculeGroup &moleculegroup, const Integrator &integrator, const PropertyMap &map) - : ConcreteProperty(map), - intgrator(integrator), timestep(1*femtosecond), num_moves(0), - total_time(0) + : ConcreteProperty(map), + intgrator(integrator), timestep(1 * femtosecond), num_moves(0), + total_time(0) { wspace = intgrator.read().createWorkspace(moleculegroup, map); - Dynamics::setEnsemble( intgrator.read().ensemble() ); + Dynamics::setEnsemble(intgrator.read().ensemble()); } /** Construct a move for the passed molecule group, integrated with the passed timestep */ MolecularDynamics::MolecularDynamics(const MoleculeGroup &molgroup, Time t, const PropertyMap &map) - : ConcreteProperty(map), - intgrator( VelocityVerlet() ), timestep(t), num_moves(0), - total_time(0) + : ConcreteProperty(map), + intgrator(VelocityVerlet()), timestep(t), num_moves(0), + total_time(0) { wspace = intgrator.read().createWorkspace(molgroup, map); - Dynamics::setEnsemble( intgrator.read().ensemble() ); + Dynamics::setEnsemble(intgrator.read().ensemble()); } /** Construct a move for the passed molecule group, integrated @@ -140,28 +137,30 @@ MolecularDynamics::MolecularDynamics(const MoleculeGroup &molgroup, MolecularDynamics::MolecularDynamics(const MoleculeGroup &molgroup, const Integrator &integrator, Time t, const PropertyMap &map) - : ConcreteProperty(map), - intgrator(integrator), timestep(t), num_moves(0), - total_time(0) + : ConcreteProperty(map), + intgrator(integrator), timestep(t), num_moves(0), + total_time(0) { wspace = intgrator.read().createWorkspace(molgroup, map); - Dynamics::setEnsemble( intgrator.read().ensemble() ); + Dynamics::setEnsemble(intgrator.read().ensemble()); } /** Copy constructor */ MolecularDynamics::MolecularDynamics(const MolecularDynamics &other) - : ConcreteProperty(other), - intgrator(other.intgrator), wspace(other.wspace), - timestep(other.timestep), num_moves(other.num_moves), - total_time(other.total_time) -{} + : ConcreteProperty(other), + intgrator(other.intgrator), wspace(other.wspace), + timestep(other.timestep), num_moves(other.num_moves), + total_time(other.total_time) +{ +} /** Destructor */ MolecularDynamics::~MolecularDynamics() -{} +{ +} /** Copy assignment operator */ -MolecularDynamics& MolecularDynamics::operator=(const MolecularDynamics &other) +MolecularDynamics &MolecularDynamics::operator=(const MolecularDynamics &other) { if (this != &other) { @@ -198,9 +197,9 @@ bool MolecularDynamics::operator!=(const MolecularDynamics &other) const QString MolecularDynamics::toString() const { return QObject::tr("MolecularDynamics( %1, timeStep() == %2 fs, nMoves() == %3 )") - .arg(intgrator->toString()) - .arg(timestep.to(femtosecond)) - .arg(num_moves); + .arg(intgrator->toString()) + .arg(timestep.to(femtosecond)) + .arg(num_moves); } /** Return the number of moves completed using this object */ @@ -216,14 +215,14 @@ SireUnits::Dimension::Time MolecularDynamics::totalTime() const } /** Return the molecule group on which this move operates */ -const MoleculeGroup& MolecularDynamics::moleculeGroup() const +const MoleculeGroup &MolecularDynamics::moleculeGroup() const { return wspace.read().moleculeGroup(); } /** Return the integrator used to advance the coordinates from one timestep to the next */ -const Integrator& MolecularDynamics::integrator() const +const Integrator &MolecularDynamics::integrator() const { return intgrator.read(); } @@ -258,8 +257,8 @@ void MolecularDynamics::setIntegrator(const Integrator &integrator) if (intgrator != integrator) { intgrator = integrator; - wspace = intgrator.read().createWorkspace( moleculeGroup(), propertyMap() ); - Dynamics::setEnsemble( intgrator.read().ensemble() ); + wspace = intgrator.read().createWorkspace(moleculeGroup(), propertyMap()); + Dynamics::setEnsemble(intgrator.read().ensemble()); } } @@ -364,24 +363,23 @@ MolarEnergy MolecularDynamics::kineticEnergy() const /** Return the temperature of the system at the last move */ Temperature MolecularDynamics::temperature() const { - SireUnits::Dimension::MolarEnergy ekin = MolecularDynamics::kineticEnergy(); - - // NOTE THAT THIS ONLY WORKS FOR 3D SPACE WHEN THERE IS ONE ATOM PER MOLECULE - // AND NO CONSTRAINTS...IN OTHER WORDS..NEED TO FIX THIS - //int ndofs = 3 * wspace.read().nMolecules(); - int ndofs = 3 * 256; + SireUnits::Dimension::MolarEnergy ekin = MolecularDynamics::kineticEnergy(); - SireUnits::Dimension::Temperature temp = ( ( 2 * ekin.value() ) / ( ndofs * k_boltz ) ) * kelvin ; + // NOTE THAT THIS ONLY WORKS FOR 3D SPACE WHEN THERE IS ONE ATOM PER MOLECULE + // AND NO CONSTRAINTS...IN OTHER WORDS..NEED TO FIX THIS + // int ndofs = 3 * wspace.read().nMolecules(); + int ndofs = 3 * 256; - return temp; + SireUnits::Dimension::Temperature temp = ((2 * ekin.value()) / (ndofs * k_boltz.value())) * kelvin; + return temp; } /** Completely clear any move statistics - this clears all existing velocities */ void MolecularDynamics::clearStatistics() { - wspace = intgrator.read().createWorkspace( moleculeGroup(), propertyMap() ); + wspace = intgrator.read().createWorkspace(moleculeGroup(), propertyMap()); num_moves = 0; total_time = Time(0); } @@ -410,9 +408,9 @@ void MolecularDynamics::move(System &system, int nmoves, bool record_stats) if (nmoves <= 0) return; - //first, calculate the energy of the system - this is to prevent a - //weird bug that causes systems to blow up if the energy has not been - //calculated - THIS NEEDS FIXING! + // first, calculate the energy of the system - this is to prevent a + // weird bug that causes systems to blow up if the energy has not been + // calculated - THIS NEEDS FIXING! system.energy(); MolecularDynamics old_state(*this); @@ -429,9 +427,9 @@ void MolecularDynamics::move(System &system, int nmoves, bool record_stats) system = wspace.read().system(); num_moves += nmoves; - total_time += nmoves*timestep; + total_time += nmoves * timestep; } - catch(...) + catch (...) { system = old_system_state; this->operator=(old_state); @@ -440,12 +438,12 @@ void MolecularDynamics::move(System &system, int nmoves, bool record_stats) } } -const char* MolecularDynamics::typeName() +const char *MolecularDynamics::typeName() { - return QMetaType::typeName( qMetaTypeId() ); + return QMetaType::typeName(qMetaTypeId()); } -MolecularDynamics* MolecularDynamics::clone() const +MolecularDynamics *MolecularDynamics::clone() const { return new MolecularDynamics(*this); } diff --git a/corelib/src/libs/SireMove/repexmove.cpp b/corelib/src/libs/SireMove/repexmove.cpp index b3d3f20aa..dd6e1c83c 100644 --- a/corelib/src/libs/SireMove/repexmove.cpp +++ b/corelib/src/libs/SireMove/repexmove.cpp @@ -66,7 +66,7 @@ static const RegisterMetaType r_repexsubmove; /** Serialise to a binary datastream */ QDataStream &operator<<(QDataStream &ds, - const RepExSubMove &repexsubmove) + const RepExSubMove &repexsubmove) { writeHeader(ds, r_repexsubmove, 2); @@ -85,7 +85,7 @@ QDataStream &operator<<(QDataStream &ds, sds << repexsubmove.need_volume; - sds << static_cast(repexsubmove); + sds << static_cast(repexsubmove); return ds; } @@ -101,15 +101,13 @@ QDataStream &operator>>(QDataStream &ds, RepExSubMove &repexsubmove) SharedDataStream sds(ds); - sds >> new_submove.partner_properties - >> new_submove.have_new_vals; + sds >> new_submove.partner_properties >> new_submove.have_new_vals; if (new_submove.have_new_vals) { double new_volume_i, new_energy_i, new_volume_j, new_energy_j; - sds >> new_volume_i >> new_energy_i - >> new_volume_j >> new_energy_j; + sds >> new_volume_i >> new_energy_i >> new_volume_j >> new_energy_j; new_submove.new_volume_i = new_volume_i * angstrom3; new_submove.new_energy_i = new_energy_i * kcal_per_mol; @@ -123,26 +121,27 @@ QDataStream &operator>>(QDataStream &ds, RepExSubMove &repexsubmove) else new_submove.need_volume = true; - sds >> static_cast(new_submove); + sds >> static_cast(new_submove); - //check that all of the partner properties are valid... - for (QList< QPair >::const_iterator - it = new_submove.partner_properties.constBegin(); + // check that all of the partner properties are valid... + for (QList>::const_iterator + it = new_submove.partner_properties.constBegin(); it != new_submove.partner_properties.constEnd(); ++it) { switch (it->first) { - case RepExSubMove::LAMBDA_VALUE: - case RepExSubMove::NRG_COMPONENT: - case RepExSubMove::SPACE_PROPERTY: - break; - - default: - throw version_error( QObject::tr( - "Version 1 of SireMove::RepExSubMove does not support " - "the partner property with ID %2.") - .arg(it->first), CODELOC ); + case RepExSubMove::LAMBDA_VALUE: + case RepExSubMove::NRG_COMPONENT: + case RepExSubMove::SPACE_PROPERTY: + break; + + default: + throw version_error(QObject::tr( + "Version 1 of SireMove::RepExSubMove does not support " + "the partner property with ID %2.") + .arg(it->first), + CODELOC); } } @@ -156,67 +155,70 @@ QDataStream &operator>>(QDataStream &ds, RepExSubMove &repexsubmove) /** Constructor */ RepExSubMove::RepExSubMove() - : ConcreteProperty(), - new_volume_i(0), new_energy_i(0), - new_volume_j(0), new_energy_j(0), - have_new_vals(false), need_volume(false) -{} + : ConcreteProperty(), + new_volume_i(0), new_energy_i(0), + new_volume_j(0), new_energy_j(0), + have_new_vals(false), need_volume(false) +{ +} /** Internal function used to add a property of our partner replica that differs from the value in this replica */ -template +template void RepExSubMove::addPartnerProperty(quint32 property, const T &value) { - partner_properties.append( QPair(property, - QVariant::fromValue(value)) ); + partner_properties.append(QPair(property, + QVariant::fromValue(value))); } /** Construct the sub-move that will perform a move on 'replica_a', after which it will then calculate the values necessary to test the swap from 'replica_a' to 'replica_b' */ RepExSubMove::RepExSubMove(const Replica &replica_a, const Replica &replica_b) - : ConcreteProperty(), - new_volume_i(0), new_energy_i(0), - new_volume_j(0), new_energy_j(0), - have_new_vals(false) + : ConcreteProperty(), + new_volume_i(0), new_energy_i(0), + new_volume_j(0), new_energy_j(0), + have_new_vals(false) { need_volume = replica_a.ensemble().isConstantPressure() and replica_b.ensemble().isConstantPressure(); if (replica_b.lambdaValue() != replica_a.lambdaValue()) { - addPartnerProperty( LAMBDA_VALUE, replica_b.lambdaValue() ); + addPartnerProperty(LAMBDA_VALUE, replica_b.lambdaValue()); } if (replica_b.energyComponent() != replica_a.energyComponent()) { - addPartnerProperty( NRG_COMPONENT, replica_b.energyComponent() ); + addPartnerProperty(NRG_COMPONENT, replica_b.energyComponent()); } if (need_volume) { if (replica_b.spaceProperty() != replica_a.spaceProperty()) { - addPartnerProperty( SPACE_PROPERTY, replica_b.spaceProperty() ); + addPartnerProperty(SPACE_PROPERTY, replica_b.spaceProperty()); } } } /** Copy constructor */ RepExSubMove::RepExSubMove(const RepExSubMove &other) - : ConcreteProperty(other), - new_volume_i(other.new_volume_i), new_energy_i(other.new_energy_i), - new_volume_j(other.new_volume_j), new_energy_j(other.new_energy_j), - partner_properties(other.partner_properties), - have_new_vals(other.have_new_vals), need_volume(other.need_volume) -{} + : ConcreteProperty(other), + new_volume_i(other.new_volume_i), new_energy_i(other.new_energy_i), + new_volume_j(other.new_volume_j), new_energy_j(other.new_energy_j), + partner_properties(other.partner_properties), + have_new_vals(other.have_new_vals), need_volume(other.need_volume) +{ +} /** Destructor */ RepExSubMove::~RepExSubMove() -{} +{ +} /** Copy assignment operator */ -RepExSubMove& RepExSubMove::operator=(const RepExSubMove &other) +RepExSubMove &RepExSubMove::operator=(const RepExSubMove &other) { if (this != &other) { @@ -241,13 +243,13 @@ RepExSubMove& RepExSubMove::operator=(const RepExSubMove &other) bool RepExSubMove::operator==(const RepExSubMove &other) const { return (this == &other) or - ( have_new_vals == other.have_new_vals and - need_volume == other.need_volume and - new_volume_i == other.new_volume_i and - new_energy_i == other.new_energy_i and - new_volume_j == other.new_volume_j and - new_energy_j == other.new_energy_j and - SupraSubMove::operator==(other) ); + (have_new_vals == other.have_new_vals and + need_volume == other.need_volume and + new_volume_i == other.new_volume_i and + new_energy_i == other.new_energy_i and + new_volume_j == other.new_volume_j and + new_energy_j == other.new_energy_j and + SupraSubMove::operator==(other)); } /** Comparison operator */ @@ -263,37 +265,39 @@ QString RepExSubMove::toString() const { if (need_volume) { - return QObject::tr( "RepExSubMove( E_i = %1 kcal mol-1, V_i = %2 A^3 : " - "E_j = %3 kcal mol-1, V_j = %4 A^3 )") - .arg( new_energy_i.to(kcal_per_mol) ) - .arg( new_volume_i.to(angstrom3) ) - .arg( new_energy_j.to(kcal_per_mol) ) - .arg( new_volume_j.to(angstrom3) ); + return QObject::tr("RepExSubMove( E_i = %1 kcal mol-1, V_i = %2 A^3 : " + "E_j = %3 kcal mol-1, V_j = %4 A^3 )") + .arg(new_energy_i.to(kcal_per_mol)) + .arg(new_volume_i.to(angstrom3)) + .arg(new_energy_j.to(kcal_per_mol)) + .arg(new_volume_j.to(angstrom3)); } else { - return QObject::tr( "RepExSubMove( E_i = %1 kcal mol-1 : " - "E_j = %2 kcal mol-1 )") - .arg( new_energy_i.to(kcal_per_mol) ) - .arg( new_energy_j.to(kcal_per_mol) ); + return QObject::tr("RepExSubMove( E_i = %1 kcal mol-1 : " + "E_j = %2 kcal mol-1 )") + .arg(new_energy_i.to(kcal_per_mol)) + .arg(new_energy_j.to(kcal_per_mol)); } } else - return QObject::tr( "RepExSubMove()" ); + return QObject::tr("RepExSubMove()"); } static void throwNoValues(const char *value, const QString &codeloc) { - throw SireError::invalid_state( QObject::tr( - "Cannot get the value of %1 as new values have not been evaluated!") - .arg(value), codeloc ); + throw SireError::invalid_state(QObject::tr( + "Cannot get the value of %1 as new values have not been evaluated!") + .arg(value), + codeloc); } static void throwNoVolume(const char *value, const QString &codeloc) { - throw SireError::invalid_state( QObject::tr( - "Cannot get the volume %1 as the move indicated that volumes weren't necessary!") - .arg(value), codeloc ); + throw SireError::invalid_state(QObject::tr( + "Cannot get the volume %1 as the move indicated that volumes weren't necessary!") + .arg(value), + codeloc); } /** Return the energy of the replica in its normal state at the @@ -301,7 +305,7 @@ static void throwNoVolume(const char *value, const QString &codeloc) MolarEnergy RepExSubMove::energy_i() const { if (not have_new_vals) - ::throwNoValues( "E_i", CODELOC ); + ::throwNoValues("E_i", CODELOC); return new_energy_i; } @@ -311,10 +315,10 @@ MolarEnergy RepExSubMove::energy_i() const Volume RepExSubMove::volume_i() const { if (not have_new_vals) - ::throwNoValues( "V_i", CODELOC ); + ::throwNoValues("V_i", CODELOC); if (not need_volume) - ::throwNoVolume( "V_i", CODELOC ); + ::throwNoVolume("V_i", CODELOC); return new_volume_i; } @@ -324,7 +328,7 @@ Volume RepExSubMove::volume_i() const MolarEnergy RepExSubMove::energy_j() const { if (not have_new_vals) - ::throwNoValues( "E_j", CODELOC ); + ::throwNoValues("E_j", CODELOC); return new_energy_j; } @@ -334,10 +338,10 @@ MolarEnergy RepExSubMove::energy_j() const Volume RepExSubMove::volume_j() const { if (not have_new_vals) - ::throwNoValues( "V_j", CODELOC ); + ::throwNoValues("V_j", CODELOC); if (not need_volume) - ::throwNoVolume( "V_j", CODELOC ); + ::throwNoVolume("V_j", CODELOC); return new_volume_j; } @@ -347,15 +351,16 @@ Volume RepExSubMove::volume_j() const \throw SireError::invalid_cast */ -template +template static T convert(const QVariant &value) { if (not value.canConvert()) - throw SireError::invalid_cast( QObject::tr( - "Cannot apply a deferred command as the argument of type %1 " - "cannot be cast to a value of type %2.") - .arg( typeid(T).name() ) - .arg( QVariant::typeToName(value.type()) ), CODELOC ); + throw SireError::invalid_cast(QObject::tr( + "Cannot apply a deferred command as the argument of type %1 " + "cannot be cast to a value of type %2.") + .arg(typeid(T).name()) + .arg(QVariant::typeToName(value.type())), + CODELOC); return value.value(); } @@ -372,7 +377,7 @@ void RepExSubMove::evaluateSwappedState(const Replica &replica) if (state_i.isPacked()) state_i.unpack(); - //get the energy and volume at this state + // get the energy and volume at this state new_energy_i = state_i.energy(); if (need_volume) @@ -390,41 +395,43 @@ void RepExSubMove::evaluateSwappedState(const Replica &replica) Symbol nrg_component = state_i.energyComponent(); PropertyName space_property = state_i.spaceProperty(); - for (QList< QPair >::const_iterator - it = partner_properties.constBegin(); + for (QList>::const_iterator + it = partner_properties.constBegin(); it != partner_properties.constEnd(); ++it) { switch (it->first) { - case LAMBDA_VALUE: - { - if (state_i.lambdaComponent().isNull()) - throw SireError::incompatible_error( QObject::tr( - "Cannot set the lambda value for a replica that doesn't " - "have a lambda component!"), CODELOC ); - - //set a new lambda value - state_j.setComponent( state_i.lambdaComponent(), - ::convert(it->second) ); - break; - } - case NRG_COMPONENT: - //set a new Hamiltonian (represented by the component) - nrg_component = ::convert(it->second); - break; - - case SPACE_PROPERTY: - //set a new space property - space_property = ::convert(it->second); - break; - - default: - throw SireError::unsupported( QObject::tr( - "A request was made of an unsuppoted action in RepExSubMove. " - "The action with ID %1 was requested, but this is not " - "supported with this version of RepExSubMove.") - .arg(it->first), CODELOC ); + case LAMBDA_VALUE: + { + if (state_i.lambdaComponent().isNull()) + throw SireError::incompatible_error(QObject::tr( + "Cannot set the lambda value for a replica that doesn't " + "have a lambda component!"), + CODELOC); + + // set a new lambda value + state_j.setComponent(state_i.lambdaComponent(), + ::convert(it->second)); + break; + } + case NRG_COMPONENT: + // set a new Hamiltonian (represented by the component) + nrg_component = ::convert(it->second); + break; + + case SPACE_PROPERTY: + // set a new space property + space_property = ::convert(it->second); + break; + + default: + throw SireError::unsupported(QObject::tr( + "A request was made of an unsuppoted action in RepExSubMove. " + "The action with ID %1 was requested, but this is not " + "supported with this version of RepExSubMove.") + .arg(it->first), + CODELOC); } } @@ -441,7 +448,7 @@ void RepExSubMove::evaluateSwappedState(const Replica &replica) void RepExSubMove::move(SupraSubSystem &system, int n_supra_moves, int n_supra_moves_per_block, bool record_stats) { - //replica exchange moves work only with Replica objects + // replica exchange moves work only with Replica objects Replica &replica = system.asA(); SupraSubSystemPtr old_replica = replica.clone(); @@ -459,26 +466,26 @@ void RepExSubMove::move(SupraSubSystem &system, int n_supra_moves, return; } - //unpack the system, if necessary + // unpack the system, if necessary bool replica_was_packed = replica.isPacked(); replica.unpack(); - //perform the moves - for (int i=0; i= n_supra_moves_per_block) this->evaluateSwappedState(replica); - //repack the system, if necessary + // repack the system, if necessary if (replica_was_packed) replica.pack(); } - catch(...) + catch (...) { replica.copy(*old_replica); this->copy(*old_state); @@ -487,9 +494,9 @@ void RepExSubMove::move(SupraSubSystem &system, int n_supra_moves, } } -const char* RepExSubMove::typeName() +const char *RepExSubMove::typeName() { - return QMetaType::typeName( qMetaTypeId() ); + return QMetaType::typeName(qMetaTypeId()); } //////////// @@ -510,7 +517,7 @@ QDataStream &operator<<(QDataStream &ds, const RepExMove &repexmove) << repexmove.nreject << repexmove.swap_monitors << repexmove.disable_swaps - << static_cast(repexmove); + << static_cast(repexmove); return ds; } @@ -526,22 +533,13 @@ QDataStream &operator>>(QDataStream &ds, RepExMove &repexmove) { SharedDataStream sds(ds); - sds >> repexmove.rangenerator - >> repexmove.naccept - >> repexmove.nreject - >> repexmove.swap_monitors - >> repexmove.disable_swaps - >> static_cast(repexmove); + sds >> repexmove.rangenerator >> repexmove.naccept >> repexmove.nreject >> repexmove.swap_monitors >> repexmove.disable_swaps >> static_cast(repexmove); } else if (v == 2) { SharedDataStream sds(ds); - sds >> repexmove.rangenerator - >> repexmove.naccept - >> repexmove.nreject - >> repexmove.swap_monitors - >> static_cast(repexmove); + sds >> repexmove.rangenerator >> repexmove.naccept >> repexmove.nreject >> repexmove.swap_monitors >> static_cast(repexmove); } else if (v == 1) { @@ -549,10 +547,7 @@ QDataStream &operator>>(QDataStream &ds, RepExMove &repexmove) quint32 nmoves; - sds >> repexmove.rangenerator - >> nmoves - >> repexmove.naccept - >> repexmove.nreject; + sds >> repexmove.rangenerator >> nmoves >> repexmove.naccept >> repexmove.nreject; repexmove.swap_monitors = false; } @@ -564,24 +559,27 @@ QDataStream &operator>>(QDataStream &ds, RepExMove &repexmove) /** Constructor */ RepExMove::RepExMove() - : ConcreteProperty(), - naccept(0), nreject(0), swap_monitors(false), disable_swaps(false) -{} + : ConcreteProperty(), + naccept(0), nreject(0), swap_monitors(false), disable_swaps(false) +{ +} /** Copy constructor */ RepExMove::RepExMove(const RepExMove &other) - : ConcreteProperty(other), - naccept(other.naccept), nreject(other.nreject), - swap_monitors(other.swap_monitors), - disable_swaps(other.disable_swaps) -{} + : ConcreteProperty(other), + naccept(other.naccept), nreject(other.nreject), + swap_monitors(other.swap_monitors), + disable_swaps(other.disable_swaps) +{ +} /** Destructor */ RepExMove::~RepExMove() -{} +{ +} /** Copy assignment operator */ -RepExMove& RepExMove::operator=(const RepExMove &other) +RepExMove &RepExMove::operator=(const RepExMove &other) { if (this != &other) { @@ -657,9 +655,9 @@ double RepExMove::acceptanceRatio() const QString RepExMove::toString() const { return QObject::tr("RepExMove( %1 accepted, %2 rejected : %3 %% )") - .arg(this->nAccepted()) - .arg(this->nRejected()) - .arg(100 * this->acceptanceRatio()); + .arg(this->nAccepted()) + .arg(this->nRejected()) + .arg(100 * this->acceptanceRatio()); } /** Clear the move statistics */ @@ -677,7 +675,7 @@ void RepExMove::setGenerator(const RanGenerator &generator) } /** Return the random number generator used for the replica exchange tests */ -const RanGenerator& RepExMove::generator() const +const RanGenerator &RepExMove::generator() const { return rangenerator; } @@ -694,34 +692,34 @@ static SupraSubSim submitSimulation(Nodes &nodes, const Replica &replica, { Node node = nodes.getNode(); - return SupraSubSim::run( node, replica, RepExSubMove(), 1, record_stats ); + return SupraSubSim::run(node, replica, RepExSubMove(), 1, record_stats); } /** Internal function used to submit the two simulations for the replicas 'replica_a' and 'replica_b', telling each simulation to follow the simulation by evaluating the values necessary to perform a swap test between these two replicas */ -static QPair submitSimulation( - Nodes &nodes, const Replica &replica_a, - const Replica &replica_b, bool record_stats) +static QPair submitSimulation( + Nodes &nodes, const Replica &replica_a, + const Replica &replica_b, bool record_stats) { - QPair sims; + QPair sims; - //submit each simulation in a separate scope so that - //the node is released once the simulation has finished + // submit each simulation in a separate scope so that + // the node is released once the simulation has finished { Node node_a = nodes.getNode(); - sims.first = SupraSubSim::run( node_a, replica_a, - RepExSubMove(replica_a, replica_b), - 1, record_stats ); + sims.first = SupraSubSim::run(node_a, replica_a, + RepExSubMove(replica_a, replica_b), + 1, record_stats); } Node node_b = nodes.getNode(); - sims.second = SupraSubSim::run( node_b, replica_b, - RepExSubMove(replica_b, replica_a), - 1, record_stats ); + sims.second = SupraSubSim::run(node_b, replica_b, + RepExSubMove(replica_b, replica_a), + 1, record_stats); return sims; } @@ -738,8 +736,8 @@ static QVector submitSimulations(Nodes &nodes, Replicas &replicas, QVector subsims(nreplicas); - //pair the replicas up... - //do we swap the even pairs or the odd pairs? + // pair the replicas up... + // do we swap the even pairs or the odd pairs? int start = 1; if (even_pairs) @@ -747,26 +745,26 @@ static QVector submitSimulations(Nodes &nodes, Replicas &replicas, if (start == 1) { - //the first replica hasn't got a partner - start it on its own + // the first replica hasn't got a partner - start it on its own subsims[0] = ::submitSimulation(nodes, replicas[0], record_stats); } - if ( (nreplicas-start) % 2 == 1 ) + if ((nreplicas - start) % 2 == 1) { - //the last replica hasn't got a partner - start it on its own too - subsims[nreplicas-1] = ::submitSimulation(nodes, replicas[nreplicas-1], - record_stats ); + // the last replica hasn't got a partner - start it on its own too + subsims[nreplicas - 1] = ::submitSimulation(nodes, replicas[nreplicas - 1], + record_stats); } - for (int i=start; i sims = ::submitSimulation( nodes, replicas[i], - replicas[i+1], - record_stats ); + // submit the simulations for replica i and replica i+1 + QPair sims = ::submitSimulation(nodes, replicas[i], + replicas[i + 1], + record_stats); subsims[i] = sims.first; - subsims[i+1] = sims.second; + subsims[i + 1] = sims.second; } return subsims; @@ -791,7 +789,7 @@ static void waitUntilFinished(Nodes &nodes, QVector &subsims, int m all_finished = true; - for (int i=0; i &subsims, int m if (subsim.isError() or subsim.wasAborted()) { - //resubmit this calculation + // resubmit this calculation Node node = nodes.getNode(); subsim = SupraSubSim::run(node, subsim.input()); @@ -807,11 +805,11 @@ static void waitUntilFinished(Nodes &nodes, QVector &subsims, int m } else if (not subsim.hasFinished()) { - //continue the calculation from where it finished + // continue the calculation from where it finished SupraSubSimPacket simpacket = subsim.result(); Node node = nodes.getNode(); - subsim = SupraSubSim::run( node, simpacket ); + subsim = SupraSubSim::run(node, simpacket); all_finished = false; } @@ -819,8 +817,8 @@ static void waitUntilFinished(Nodes &nodes, QVector &subsims, int m if (not all_finished) { - //wait for the resubmitted calculations to finish - for (int i=0; i &subsims, int m bool RepExMove::testPair(const Replica &replica_a, const RepExSubMove &move_a, const Replica &replica_b, const RepExSubMove &move_b) const { - //get the ensembles of the two replicas + // get the ensembles of the two replicas const Ensemble &ensemble_a = replica_a.ensemble(); const Ensemble &ensemble_b = replica_b.ensemble(); - if ( (ensemble_a.isNVT() and ensemble_a.isNVT()) or - (ensemble_b.isNPT() and ensemble_b.isNPT()) ) + if ((ensemble_a.isNVT() and ensemble_a.isNVT()) or + (ensemble_b.isNPT() and ensemble_b.isNPT())) { bool need_pv = (ensemble_a.isNPT() and ensemble_b.isNPT()); - //get the values of the thermodynamic parameters - double beta_a = 1.0 / (k_boltz * ensemble_a.temperature()).value(); - double beta_b = 1.0 / (k_boltz * ensemble_b.temperature()).value(); + // get the values of the thermodynamic parameters + double beta_a = 1.0 / (k_boltz.value() * ensemble_a.temperature()).value(); + double beta_b = 1.0 / (k_boltz.value() * ensemble_b.temperature()).value(); Pressure p_a(0); Pressure p_b(0); @@ -855,8 +853,8 @@ bool RepExMove::testPair(const Replica &replica_a, const RepExSubMove &move_a, p_b = ensemble_b.pressure(); } - //now get the values of the system properties at their current state, - //and at their swapped states + // now get the values of the system properties at their current state, + // and at their swapped states MolarEnergy H_a_i = move_a.energy_i(); MolarEnergy H_a_j = move_a.energy_j(); @@ -878,28 +876,28 @@ bool RepExMove::testPair(const Replica &replica_a, const RepExSubMove &move_a, V_b_j = move_b.volume_j(); } - //now calculate delta needed for the Monte Carlo test + // now calculate delta needed for the Monte Carlo test // - // For derivation see Appendix C of Christopher Woods' thesis - // (or original replica exchange literature of course!) + // For derivation see Appendix C of Christopher Woods' thesis + // (or original replica exchange literature of course!) // - // delta = beta_b * [ H_b_i - H_b_j + P_b (V_b_i - V_b_j) ] + - // beta_a * [ H_a_i - H_a_j + P_a (V_a_i - V_a_j) ] + // delta = beta_b * [ H_b_i - H_b_j + P_b (V_b_i - V_b_j) ] + + // beta_a * [ H_a_i - H_a_j + P_a (V_a_i - V_a_j) ] - double delta = beta_b * ( H_b_i - H_b_j + p_b*(V_b_i - V_b_j) ) + - beta_a * ( H_a_i - H_a_j + p_a*(V_a_i - V_a_j) ); + double delta = beta_b * (H_b_i - H_b_j + p_b * (V_b_i - V_b_j)) + + beta_a * (H_a_i - H_a_j + p_a * (V_a_i - V_a_j)); - bool move_passed = ( delta > 0 or (std::exp(delta) >= rangenerator.rand()) ); + bool move_passed = (delta > 0 or (std::exp(delta) >= rangenerator.rand())); return move_passed; } else { - throw SireError::incompatible_error( QObject::tr( - "There is no available replica exchange test that allows tests between " - "replicas with ensembles %1 and %2.") - .arg(ensemble_a.toString(), ensemble_b.toString()), CODELOC ); - + throw SireError::incompatible_error(QObject::tr( + "There is no available replica exchange test that allows tests between " + "replicas with ensembles %1 and %2.") + .arg(ensemble_a.toString(), ensemble_b.toString()), + CODELOC); } return false; @@ -918,16 +916,16 @@ void RepExMove::testAndSwap(Replicas &replicas, const QVector &sub if (even_pairs) start = 0; - //loop over all pairs - for (int i=start; itestPair(replicas[i], submoves.at(i), - replicas[i+1], submoves.at(i+1) )) + replicas[i + 1], submoves.at(i + 1))) { - //swap the replicas - replicas.swapSystems(i, i+1, swap_monitors); + // swap the replicas + replicas.swapSystems(i, i + 1, swap_monitors); ++naccept; } else @@ -942,43 +940,42 @@ void RepExMove::testAndSwap(Replicas &replicas, const QVector &sub pairs */ void RepExMove::performMove(Nodes &nodes, Replicas &replicas, bool record_stats) { - //will we swap even pairs or odd pairs? + // will we swap even pairs or odd pairs? bool even_pairs = true; if (replicas.nReplicas() > 2) even_pairs = rangenerator.randBool(); - //submit all of the simulations + // submit all of the simulations QVector subsims = ::submitSimulations(nodes, replicas, even_pairs, record_stats); - //wait for all of the simulations to finish (retrying broken simulations - //just five times) + // wait for all of the simulations to finish (retrying broken simulations + // just five times) ::waitUntilFinished(nodes, subsims, 5); - //copy the results back into the replicas + // copy the results back into the replicas int nreplicas = replicas.count(); QVector submoves(nreplicas); submoves.squeeze(); - for (int i=0; i()[0] - .asA(); + submoves[i] = subsims[i].result().subMoves().asA()[0].asA(); - replicas.setReplica( i, subsims[i].result().subSystem() ); + replicas.setReplica(i, subsims[i].result().subSystem()); } - //get rid of the simulation handles, as they are no longer needed + // get rid of the simulation handles, as they are no longer needed //(and we need to save memory if we can) subsims = QVector(); - //now perform all of the replica exchange tests + // now perform all of the replica exchange tests if (not disable_swaps) this->testAndSwap(replicas, submoves, even_pairs, record_stats); - //now collect any necessary statistics + // now collect any necessary statistics if (record_stats) replicas.collectSupraStats(); } @@ -1002,14 +999,14 @@ void RepExMove::move(SupraSystem &system, int nmoves, bool record_stats) try { - //try to get as many nodes as possible to run the moves - Nodes nodes = Cluster::getNodes( replicas.nReplicas() - 1, 5000 ); + // try to get as many nodes as possible to run the moves + Nodes nodes = Cluster::getNodes(replicas.nReplicas() - 1, 5000); - ///hold this_thread in a local scope to ensure it is deleted before 'nodes' + /// hold this_thread in a local scope to ensure it is deleted before 'nodes' { ThisThread this_thread = nodes.borrowThisThread(); - for (int i=0; iperformMove(nodes, replicas, record_stats); } @@ -1017,7 +1014,7 @@ void RepExMove::move(SupraSystem &system, int nmoves, bool record_stats) SupraMove::incrementNMoves(nmoves); } } - catch(...) + catch (...) { replicas.copy(*old_replicas); this->copy(*old_state); @@ -1025,7 +1022,7 @@ void RepExMove::move(SupraSystem &system, int nmoves, bool record_stats) } } -const char* RepExMove::typeName() +const char *RepExMove::typeName() { - return QMetaType::typeName( qMetaTypeId() ); + return QMetaType::typeName(qMetaTypeId()); } diff --git a/corelib/src/libs/SireMove/repexmove2.cpp b/corelib/src/libs/SireMove/repexmove2.cpp index 683c19174..8e6b83aa9 100644 --- a/corelib/src/libs/SireMove/repexmove2.cpp +++ b/corelib/src/libs/SireMove/repexmove2.cpp @@ -42,7 +42,7 @@ #include "SireError/errors.h" // tbb::task has been deprecated! -//#include "tbb/task.h" +// #include "tbb/task.h" #include #include @@ -73,7 +73,7 @@ QDataStream &operator<<(QDataStream &ds, const RepExMove2 &repexmove2) << repexmove2.nreject << repexmove2.swap_monitors << repexmove2.disable_swaps - << static_cast(repexmove2); + << static_cast(repexmove2); return ds; } @@ -87,12 +87,7 @@ QDataStream &operator>>(QDataStream &ds, RepExMove2 &repexmove2) { SharedDataStream sds(ds); - sds >> repexmove2.rangenerator - >> repexmove2.naccept - >> repexmove2.nreject - >> repexmove2.swap_monitors - >> repexmove2.disable_swaps - >> static_cast(repexmove2); + sds >> repexmove2.rangenerator >> repexmove2.naccept >> repexmove2.nreject >> repexmove2.swap_monitors >> repexmove2.disable_swaps >> static_cast(repexmove2); } else throw version_error(v, "1", r_repexmove2, CODELOC); @@ -102,24 +97,27 @@ QDataStream &operator>>(QDataStream &ds, RepExMove2 &repexmove2) /** Constructor */ RepExMove2::RepExMove2() - : ConcreteProperty(), - naccept(0), nreject(0), swap_monitors(false), disable_swaps(false) -{} + : ConcreteProperty(), + naccept(0), nreject(0), swap_monitors(false), disable_swaps(false) +{ +} /** Copy constructor */ RepExMove2::RepExMove2(const RepExMove2 &other) - : ConcreteProperty(other), - naccept(other.naccept), nreject(other.nreject), - swap_monitors(other.swap_monitors), - disable_swaps(other.disable_swaps) -{} + : ConcreteProperty(other), + naccept(other.naccept), nreject(other.nreject), + swap_monitors(other.swap_monitors), + disable_swaps(other.disable_swaps) +{ +} /** Destructor */ RepExMove2::~RepExMove2() -{} +{ +} /** Copy assignment operator */ -RepExMove2& RepExMove2::operator=(const RepExMove2 &other) +RepExMove2 &RepExMove2::operator=(const RepExMove2 &other) { if (this != &other) { @@ -195,9 +193,9 @@ double RepExMove2::acceptanceRatio() const QString RepExMove2::toString() const { return QObject::tr("RepExMove2( %1 accepted, %2 rejected : %3 %% )") - .arg(this->nAccepted()) - .arg(this->nRejected()) - .arg(100 * this->acceptanceRatio()); + .arg(this->nAccepted()) + .arg(this->nRejected()) + .arg(100 * this->acceptanceRatio()); } /** Clear the move statistics */ @@ -215,7 +213,7 @@ void RepExMove2::setGenerator(const RanGenerator &generator) } /** Return the random number generator used for the replica exchange tests */ -const RanGenerator& RepExMove2::generator() const +const RanGenerator &RepExMove2::generator() const { return rangenerator; } @@ -298,18 +296,18 @@ void RepExMove2::setSwapMonitors(bool swap) bool replicaTest(Replica &replica_a, Replica &replica_b, const RanGenerator &rangenerator) { - //get the ensembles of the two replicas + // get the ensembles of the two replicas const Ensemble &ensemble_a = replica_a.ensemble(); const Ensemble &ensemble_b = replica_b.ensemble(); - if ( (ensemble_a.isNVT() and ensemble_a.isNVT()) or - (ensemble_b.isNPT() and ensemble_b.isNPT()) ) + if ((ensemble_a.isNVT() and ensemble_a.isNVT()) or + (ensemble_b.isNPT() and ensemble_b.isNPT())) { bool need_pv = (ensemble_a.isNPT() and ensemble_b.isNPT()); - //get the values of the thermodynamic parameters - double beta_a = 1.0 / (k_boltz * ensemble_a.temperature()).value(); - double beta_b = 1.0 / (k_boltz * ensemble_b.temperature()).value(); + // get the values of the thermodynamic parameters + double beta_a = 1.0 / (k_boltz.value() * ensemble_a.temperature()).value(); + double beta_b = 1.0 / (k_boltz.value() * ensemble_b.temperature()).value(); Pressure p_a(0); Pressure p_b(0); @@ -320,8 +318,8 @@ bool replicaTest(Replica &replica_a, Replica &replica_b, p_b = ensemble_b.pressure(); } - //now get the values of the system properties at their current state, - //and at their swapped states + // now get the values of the system properties at their current state, + // and at their swapped states double H_a_i = replica_a.energy().value(); double H_b_i = replica_b.energy().value(); @@ -331,17 +329,17 @@ bool replicaTest(Replica &replica_a, Replica &replica_b, if (replica_a.lambdaValue() != replica_b.lambdaValue() or replica_a.energyComponent() != replica_b.energyComponent()) { - //there will be a change in energy associated with the swap + // there will be a change in energy associated with the swap System swapped = replica_a.subSystem(); - //evaluate the energy of replica A swapped into the B state + // evaluate the energy of replica A swapped into the B state swapped.setComponent(replica_a.lambdaComponent(), replica_b.lambdaValue()); - H_a_j = swapped.energy( replica_b.energyComponent() ).value(); + H_a_j = swapped.energy(replica_b.energyComponent()).value(); - //evaluate the energy of replica B swapped into the A state + // evaluate the energy of replica B swapped into the A state swapped = replica_b.subSystem(); swapped.setComponent(replica_b.lambdaComponent(), replica_a.lambdaValue()); - H_b_j = swapped.energy( replica_a.energyComponent() ).value(); + H_b_j = swapped.energy(replica_a.energyComponent()).value(); } double V_a_i(0); @@ -360,37 +358,35 @@ bool replicaTest(Replica &replica_a, Replica &replica_b, if (replica_a.spaceProperty() != replica_b.spaceProperty()) { - //the space property changes, so volume could change - V_a_j = replica_a.subSystem().property(replica_b.spaceProperty()) - .asA().volume().value(); + // the space property changes, so volume could change + V_a_j = replica_a.subSystem().property(replica_b.spaceProperty()).asA().volume().value(); - V_b_j = replica_b.subSystem().property(replica_a.spaceProperty()) - .asA().volume().value(); + V_b_j = replica_b.subSystem().property(replica_a.spaceProperty()).asA().volume().value(); } } - //now calculate delta needed for the Monte Carlo test + // now calculate delta needed for the Monte Carlo test // - // For derivation see Appendix C of Christopher Woods' thesis - // (or original replica exchange literature of course!) + // For derivation see Appendix C of Christopher Woods' thesis + // (or original replica exchange literature of course!) // - // delta = beta_b * [ H_b_i - H_b_j + P_b (V_b_i - V_b_j) ] + - // beta_a * [ H_a_i - H_a_j + P_a (V_a_i - V_a_j) ] + // delta = beta_b * [ H_b_i - H_b_j + P_b (V_b_i - V_b_j) ] + + // beta_a * [ H_a_i - H_a_j + P_a (V_a_i - V_a_j) ] - double delta = beta_b * ( H_b_i - H_b_j + p_b*(V_b_i - V_b_j) ) + - beta_a * ( H_a_i - H_a_j + p_a*(V_a_i - V_a_j) ); + double delta = beta_b * (H_b_i - H_b_j + p_b * (V_b_i - V_b_j)) + + beta_a * (H_a_i - H_a_j + p_a * (V_a_i - V_a_j)); - bool move_passed = ( delta > 0 or (std::exp(delta) >= rangenerator.rand()) ); + bool move_passed = (delta > 0 or (std::exp(delta) >= rangenerator.rand())); return move_passed; } else { - throw SireError::incompatible_error( QObject::tr( - "There is no available replica exchange test that allows tests between " - "replicas with ensembles %1 and %2.") - .arg(ensemble_a.toString(), ensemble_b.toString()), CODELOC ); - + throw SireError::incompatible_error(QObject::tr( + "There is no available replica exchange test that allows tests between " + "replicas with ensembles %1 and %2.") + .arg(ensemble_a.toString(), ensemble_b.toString()), + CODELOC); } return false; @@ -559,11 +555,11 @@ bool replicaTest(Replica &replica_a, Replica &replica_b, void RepExMove2::performMove(Replicas &replicas, bool record_stats) { throw SireError::incomplete_code( - QObject::tr("tbb has removed tbb::task, so we now need to " - "rewrite RepExMove2. If this affects you, " - "please switch to RepExMove, and then raise " - "a GitHub issue asking us to conduct a rewrite."), - CODELOC); + QObject::tr("tbb has removed tbb::task, so we now need to " + "rewrite RepExMove2. If this affects you, " + "please switch to RepExMove, and then raise " + "a GitHub issue asking us to conduct a rewrite."), + CODELOC); /* if (replicas.nReplicas() == 0) return; @@ -658,14 +654,14 @@ void RepExMove2::move(SupraSystem &system, int nmoves, bool record_stats) try { - for (int i=0; iperformMove(replicas, record_stats); } SupraMove::incrementNMoves(nmoves); } - catch(...) + catch (...) { replicas.copy(*old_replicas); this->copy(*old_state); @@ -673,9 +669,7 @@ void RepExMove2::move(SupraSystem &system, int nmoves, bool record_stats) } } -const char* RepExMove2::typeName() +const char *RepExMove2::typeName() { - return QMetaType::typeName( qMetaTypeId() ); + return QMetaType::typeName(qMetaTypeId()); } - - diff --git a/corelib/src/libs/SireUnits/dimensions.h b/corelib/src/libs/SireUnits/dimensions.h index 6098529ad..14ef5a57d 100644 --- a/corelib/src/libs/SireUnits/dimensions.h +++ b/corelib/src/libs/SireUnits/dimensions.h @@ -39,436 +39,453 @@ SIRE_BEGIN_HEADER namespace SireUnits { -namespace Dimension -{ -class Unit; -class GeneralUnit; -} -} - -QDataStream& operator<<(QDataStream&, const SireUnits::Dimension::Unit&); -QDataStream& operator>>(QDataStream&, SireUnits::Dimension::Unit&); - -namespace SireUnits -{ - -using SireMaths::pi; - - -namespace Dimension -{ - -class TempBase; - -/** This is the base class of all units - at its heart, this is - just a scale factor - how many times the base unit is the - current value. - - @author Christopher Woods -*/ -class SIREUNITS_EXPORT Unit -{ - -friend SIREUNITS_EXPORT QDataStream& ::operator<<(QDataStream&, const Unit&); -friend SIREUNITS_EXPORT QDataStream& ::operator>>(QDataStream&, Unit&); - -public: - ~Unit() - {} - - operator double() const - { - return sclfac; - } - - double value() const - { - return sclfac; - } - - double scaleFactor() const - { - return sclfac; - } - - double convertToInternal(double value) const - { - return value * sclfac; - } - - double convertFromInternal(double value) const - { - return value / sclfac; - } - -protected: - Unit(double scale_factor) : sclfac(scale_factor) - {} - - Unit(const TempBase &temperature); - - void setScale(double scale_factor) - { - sclfac = scale_factor; - } - -private: - double sclfac; -}; - -SIREUNITS_EXPORT QPair getUnitString( - int M, int L, int T, int C, int t, int Q, int A); - -/** Construct a physical unit with the specified - Mass, Length, Time, Charge, temperature, - Quantity and Angle dimensions - - @author Christopher Woods -*/ -template -class PhysUnit : public Unit -{ -public: - PhysUnit() : Unit(0) - {} - - explicit PhysUnit(double scale_factor) - : Unit(scale_factor) - {} - - explicit PhysUnit(const TempBase &temperature) : Unit(temperature) - { - //this must be a Temperature! - //BOOST_STATIC_ASSERT( t == 1 and M == 0 and L == 0 and - // T == 0 and C == 0 and Q == 0 and A == 0); - } - - PhysUnit(const GeneralUnit &other); - - PhysUnit(const PhysUnit &other) - : Unit(other) - {} - - ~PhysUnit() - {} - - static const char* typeName() - { - return QMetaType::typeName( qMetaTypeId< PhysUnit >() ); - } - - const char* what() const - { - return PhysUnit::typeName(); - } - - PhysUnit& - operator=(const PhysUnit &other) - { - Unit::setScale(other.scaleFactor()); - return *this; - } - - PhysUnit& - operator=(const GeneralUnit &other); - - bool operator==(const PhysUnit &other) const - { - return scaleFactor() == other.scaleFactor(); - } - - bool operator!=(const PhysUnit &other) const - { - return scaleFactor() != other.scaleFactor(); - } - - PhysUnit operator-() const - { - return PhysUnit( -scaleFactor() ); - } - - PhysUnit - operator+(const PhysUnit &other) const - { - return PhysUnit( - scaleFactor() + other.scaleFactor()); - } - - PhysUnit - operator-(const PhysUnit &other) const - { - return PhysUnit( - scaleFactor() - other.scaleFactor()); - } - - PhysUnit& - operator+=(const PhysUnit &other) - { - Unit::setScale( scaleFactor() + other.scaleFactor() ); - return *this; - } - - PhysUnit& - operator-=(const PhysUnit &other) + namespace Dimension { - Unit::setScale( scaleFactor() - other.scaleFactor() ); - return *this; + class Unit; + class GeneralUnit; } - - PhysUnit operator*(double val) const - { - return PhysUnit(scaleFactor() * val); - } - - PhysUnit& operator*=(double val) - { - Unit::setScale( scaleFactor() * val ); - return *this; - } - - PhysUnit& operator/=(double val) - { - Unit::setScale( scaleFactor() / val ); - return *this; - } - - PhysUnit& operator*=(int val) - { - Unit::setScale( scaleFactor() * val ); - return *this; - } - - PhysUnit& operator/=(int val) - { - Unit::setScale( scaleFactor() / val ); - return *this; - } - - PhysUnit operator/(double val) const - { - return PhysUnit(scaleFactor() / val); - } - - PhysUnit operator*(int val) const - { - return PhysUnit(scaleFactor() * val); - } - - PhysUnit operator/(int val) const - { - return PhysUnit(scaleFactor() / val); - } - - template - PhysUnit - operator*(const PhysUnit<_M,_L,_T,_C,_t,_Q,_A> &other) const - { - return PhysUnit( - scaleFactor() * other.scaleFactor()); - } - - template - PhysUnit - operator/(const PhysUnit<_M,_L,_T,_C,_t,_Q,_A> &other) const - { - return PhysUnit( - scaleFactor() / other.scaleFactor()); - } - - PhysUnit<-M,-L,-T,-C,-t,-Q,-A> invert() const - { - return PhysUnit<-M,-L,-T,-C,-t,-Q,-A>( 1.0 / scaleFactor() ); - } - - double in(const PhysUnit &units) const - { - return units.convertFromInternal(*this); - } - - double to(const PhysUnit &units) const - { - return this->in(units); - } - - QString unitString() const - { - return SireUnits::Dimension::getUnitString(M, L, T, C, t, Q, A).second; - } - - QString toString() const - { - auto u = SireUnits::Dimension::getUnitString(M, L, T, C, t, Q, A); - - double v = value() / u.first; - - if (u.second.startsWith("°")) - return QString("%1%2").arg(v).arg(u.second); - else - return QString("%1 %2").arg(v).arg(u.second); - } - - static int MASS() - { - return M; - } - - static int LENGTH() - { - return L; - } - - static int TIME() - { - return T; - } - - static int CHARGE() - { - return C; - } - - static int TEMPERATURE() - { - return t; - } - - static int QUANTITY() - { - return Q; - } - - static int ANGLE() - { - return A; - } -}; - -template -PhysUnit -operator*(double val, const PhysUnit &unit) -{ - return PhysUnit( val * unit.scaleFactor() ); } -template -PhysUnit -operator*(int val, const PhysUnit &unit) -{ - return PhysUnit( val * unit.scaleFactor() ); -} +QDataStream &operator<<(QDataStream &, const SireUnits::Dimension::Unit &); +QDataStream &operator>>(QDataStream &, SireUnits::Dimension::Unit &); -template -PhysUnit<-M,-L,-T,-C,-t,-Q,-A> -operator/(double val, const PhysUnit &unit) +namespace SireUnits { - return PhysUnit<-M,-L,-T,-C,-t,-Q,-A>( val / unit.scaleFactor() ); -} -template -PhysUnit<-M,-L,-T,-C,-t,-Q,-A> -operator/(int val, const PhysUnit &unit) -{ - return PhysUnit<-M,-L,-T,-C,-t,-Q,-A>( val / unit.scaleFactor() ); -} + using SireMaths::pi; + + namespace Dimension + { + + class TempBase; + + /** This is the base class of all units - at its heart, this is + just a scale factor - how many times the base unit is the + current value. + + @author Christopher Woods + */ + class SIREUNITS_EXPORT Unit + { + + friend SIREUNITS_EXPORT QDataStream & ::operator<<(QDataStream &, const Unit &); + friend SIREUNITS_EXPORT QDataStream & ::operator>>(QDataStream &, Unit &); + + public: + ~Unit() + { + } + + operator double() const + { + return sclfac; + } + + double value() const + { + return sclfac; + } + + double scaleFactor() const + { + return sclfac; + } + + double convertToInternal(double value) const + { + return value * sclfac; + } + + double convertFromInternal(double value) const + { + return value / sclfac; + } + + protected: + Unit(double scale_factor) : sclfac(scale_factor) + { + } + + Unit(const TempBase &temperature); + + void setScale(double scale_factor) + { + sclfac = scale_factor; + } + + private: + double sclfac; + }; + + SIREUNITS_EXPORT QPair getUnitString( + int M, int L, int T, int C, int t, int Q, int A); + + /** Construct a physical unit with the specified + Mass, Length, Time, Charge, temperature, + Quantity and Angle dimensions + + @author Christopher Woods + */ + template + class PhysUnit : public Unit + { + public: + PhysUnit() : Unit(0) + { + } + + explicit PhysUnit(double scale_factor) + : Unit(scale_factor) + { + } + + explicit PhysUnit(const TempBase &temperature) : Unit(temperature) + { + // this must be a Temperature! + // BOOST_STATIC_ASSERT( t == 1 and M == 0 and L == 0 and + // T == 0 and C == 0 and Q == 0 and A == 0); + } + + PhysUnit(const GeneralUnit &other); + + PhysUnit(const PhysUnit &other) + : Unit(other) + { + } + + ~PhysUnit() + { + } + + static const char *typeName() + { + return QMetaType::typeName(qMetaTypeId>()); + } + + const char *what() const + { + return PhysUnit::typeName(); + } + + PhysUnit & + operator=(const PhysUnit &other) + { + Unit::setScale(other.scaleFactor()); + return *this; + } + + PhysUnit & + operator=(const GeneralUnit &other); + + bool operator==(const PhysUnit &other) const + { + return scaleFactor() == other.scaleFactor(); + } + + bool operator!=(const PhysUnit &other) const + { + return scaleFactor() != other.scaleFactor(); + } + + PhysUnit operator-() const + { + return PhysUnit(-scaleFactor()); + } + + PhysUnit + operator+(const PhysUnit &other) const + { + return PhysUnit( + scaleFactor() + other.scaleFactor()); + } + + PhysUnit + operator-(const PhysUnit &other) const + { + return PhysUnit( + scaleFactor() - other.scaleFactor()); + } + + PhysUnit & + operator+=(const PhysUnit &other) + { + Unit::setScale(scaleFactor() + other.scaleFactor()); + return *this; + } + + PhysUnit & + operator-=(const PhysUnit &other) + { + Unit::setScale(scaleFactor() - other.scaleFactor()); + return *this; + } + + PhysUnit operator*(double val) const + { + return PhysUnit(scaleFactor() * val); + } + + PhysUnit &operator*=(double val) + { + Unit::setScale(scaleFactor() * val); + return *this; + } + + PhysUnit &operator/=(double val) + { + Unit::setScale(scaleFactor() / val); + return *this; + } + + PhysUnit &operator*=(int val) + { + Unit::setScale(scaleFactor() * val); + return *this; + } + + PhysUnit &operator/=(int val) + { + Unit::setScale(scaleFactor() / val); + return *this; + } + + PhysUnit operator/(double val) const + { + return PhysUnit(scaleFactor() / val); + } + + PhysUnit operator*(int val) const + { + return PhysUnit(scaleFactor() * val); + } + + PhysUnit operator/(int val) const + { + return PhysUnit(scaleFactor() / val); + } + + template + PhysUnit + operator*(const PhysUnit<_M, _L, _T, _C, _t, _Q, _A> &other) const + { + return PhysUnit( + scaleFactor() * other.scaleFactor()); + } + + template + PhysUnit + operator/(const PhysUnit<_M, _L, _T, _C, _t, _Q, _A> &other) const + { + return PhysUnit( + scaleFactor() / other.scaleFactor()); + } + + PhysUnit<-M, -L, -T, -C, -t, -Q, -A> invert() const + { + return PhysUnit<-M, -L, -T, -C, -t, -Q, -A>(1.0 / scaleFactor()); + } + + double in(const PhysUnit &units) const + { + return units.convertFromInternal(*this); + } + + double to(const PhysUnit &units) const + { + return this->in(units); + } + + QString unitString() const + { + return SireUnits::Dimension::getUnitString(M, L, T, C, t, Q, A).second; + } + + QString toString() const + { + auto u = SireUnits::Dimension::getUnitString(M, L, T, C, t, Q, A); + + double v = value() / u.first; + + if (u.second.startsWith("°")) + return QString("%1%2").arg(v).arg(u.second); + else + return QString("%1 %2").arg(v).arg(u.second); + } + + static int MASS() + { + return M; + } + + static int LENGTH() + { + return L; + } + + static int TIME() + { + return T; + } + + static int CHARGE() + { + return C; + } + + static int TEMPERATURE() + { + return t; + } + + static int QUANTITY() + { + return Q; + } + + static int ANGLE() + { + return A; + } + }; + + template + PhysUnit + operator*(double val, const PhysUnit &unit) + { + return PhysUnit(val * unit.scaleFactor()); + } + + template + PhysUnit + operator*(int val, const PhysUnit &unit) + { + return PhysUnit(val * unit.scaleFactor()); + } + + template + PhysUnit<-M, -L, -T, -C, -t, -Q, -A> + operator/(double val, const PhysUnit &unit) + { + return PhysUnit<-M, -L, -T, -C, -t, -Q, -A>(val / unit.scaleFactor()); + } + + template + PhysUnit<-M, -L, -T, -C, -t, -Q, -A> + operator/(int val, const PhysUnit &unit) + { + return PhysUnit<-M, -L, -T, -C, -t, -Q, -A>(val / unit.scaleFactor()); + } /** Typedef the various unit dimensions (including derived units) */ #ifndef SKIP_BROKEN_GCCXML_PARTS -typedef PhysUnit<0,0,0,0,0,0,0> Dimensionless; + typedef PhysUnit<0, 0, 0, 0, 0, 0, 0> Dimensionless; + + typedef PhysUnit<1, 0, 0, 0, 0, 0, 0> Mass; -typedef PhysUnit<1,0,0,0,0,0,0> Mass; + typedef PhysUnit<1, 0, 0, 0, 0, -1, 0> MolarMass; -typedef PhysUnit<1,0,0,0,0,-1,0> MolarMass; + typedef PhysUnit<0, 1, 0, 0, 0, 0, 0> Length; -typedef PhysUnit<0,1,0,0,0,0,0> Length; + typedef PhysUnit<0, 0, 1, 0, 0, 0, 0> Time; -typedef PhysUnit<0,0,1,0,0,0,0> Time; + typedef PhysUnit<0, 0, 0, 1, 0, 0, 0> Charge; -typedef PhysUnit<0,0,0,1,0,0,0> Charge; + typedef PhysUnit<0, 0, 0, 1, 0, -1, 0> MolarCharge; -typedef PhysUnit<0,0,0,1,0,-1,0> MolarCharge; + typedef PhysUnit<0, 0, 0, 0, 1, 0, 0> Temperature; -typedef PhysUnit<0,0,0,0,1,0,0> Temperature; + typedef PhysUnit<0, 0, 0, 0, 0, 1, 0> Quantity; -typedef PhysUnit<0,0,0,0,0,1,0> Quantity; + typedef PhysUnit<0, 0, 0, 0, 0, 0, 1> Angle; -typedef PhysUnit<0,0,0,0,0,0,1> Angle; + typedef PhysUnit<0, 2, 0, 0, 0, 0, 0> Area; -typedef PhysUnit<0,2,0,0,0,0,0> Area; + typedef PhysUnit<0, 3, 0, 0, 0, 0, 0> Volume; -typedef PhysUnit<0,3,0,0,0,0,0> Volume; + typedef PhysUnit<0, 3, 0, 0, 0, -1, 0> MolarVolume; -typedef PhysUnit<0,3,0,0,0,-1,0> MolarVolume; + typedef PhysUnit<0, 1, -1, 0, 0, 0, 0> Velocity; -typedef PhysUnit<0,1,-1,0,0,0,0> Velocity; + typedef PhysUnit<0, 0, -1, 0, 0, 0, 1> AngularVelocity; -typedef PhysUnit<0,0,-1,0,0,0,1> AngularVelocity; + typedef PhysUnit<0, 1, -2, 0, 0, 0, 0> Acceleration; -typedef PhysUnit<0,1,-2,0,0,0,0> Acceleration; + typedef PhysUnit<0, 0, -2, 0, 0, 0, 1> AngularAcceleration; -typedef PhysUnit<0,0,-2,0,0,0,1> AngularAcceleration; + typedef PhysUnit<1, 2, -2, 0, 0, 0, 0> Energy; -typedef PhysUnit<1,2,-2,0,0,0,0> Energy; + typedef PhysUnit<1, 2, -2, 0, 0, -1, 0> MolarEnergy; -typedef PhysUnit<1,2,-2,0,0,-1,0> MolarEnergy; + typedef PhysUnit<1, 2, -3, 0, 0, 0, 0> Power; -typedef PhysUnit<1,2,-3,0,0,0,0> Power; + typedef PhysUnit<1, 2, -3, 0, 0, -1, 0> MolarPower; -typedef PhysUnit<1,2,-3,0,0,-1,0> MolarPower; + typedef PhysUnit<1, -3, 0, 0, 0, 0, 0> Density; -typedef PhysUnit<1,-3,0,0,0,0,0> Density; + typedef PhysUnit<1, -3, 0, 0, 0, -1, 0> MolarDensity; -typedef PhysUnit<1,-3,0,0,0,-1,0> MolarDensity; + typedef PhysUnit<1, 1, -2, 0, 0, 0, 0> Force; -typedef PhysUnit<1,1,-2,0,0,0,0> Force; + typedef PhysUnit<1, -1, -2, 0, 0, 0, 0> Pressure; -typedef PhysUnit<1,-1,-2,0,0,0,0> Pressure; + typedef PhysUnit<0, 0, -1, 1, 0, 0, 0> Current; + typedef PhysUnit<-1, -2, 2, 2, 0, 0, 0> Capacitance; + typedef PhysUnit<1, 2, -2, -1, 0, 0, 0> Potential; -typedef PhysUnit<0,0,-1,1,0,0,0> Current; -typedef PhysUnit<-1,-2,2,2,0,0,0> Capacitance; -typedef PhysUnit<1,2,-2,-1,0,0,0> Potential; + typedef PhysUnit<-1, -3, 2, 2, 0, 0, 0> Constant1; + typedef PhysUnit<1, 2, -1, 0, 0, 0, 0> Constant2; + typedef PhysUnit<1, 1, 0, -2, 0, 0, 0> Constant3; + typedef PhysUnit<-1, 3, -2, 0, 0, 0, 0> Constant4; + typedef PhysUnit<1, 2, -2, 0, -1, -1, 0> Constant5; #else // else with 'ifndef SKIP_BROKEN_GCCXML_PARTS' -class Dimensionless; -class Mass; -class MolarMass; -class Length; -class Time; -class Charge; -class MolarCharge; -class Temperature; -class Quantity; -class Angle; -class Area; -class Volume; -class MolarVolume; -class Velocity; -class Acceleration; -class Energy; -class MolarEnergy; -class Power; -class MolarPower; -class Density; -class MolarDensity; -class Force; -class Pressure; -class Capacitance; -class Current; -class Potential; + class Dimensionless; + class Mass; + class MolarMass; + class Length; + class Time; + class Charge; + class MolarCharge; + class Temperature; + class Quantity; + class Angle; + class Area; + class Volume; + class MolarVolume; + class Velocity; + class Acceleration; + class Energy; + class MolarEnergy; + class Power; + class MolarPower; + class Density; + class MolarDensity; + class Force; + class Pressure; + class Capacitance; + class Current; + class Potential; + + class Constant1; + class Constant2; + class Constant3; + class Constant4; + class Constant5; #endif // end of 'ifndef SKIP_BROKEN_GCCXML_PARTS' -} // end of namespace Dimension + } // end of namespace Dimension } /** Serialise a unit to a binary datastream (this does not check the type of unit!) */ -SIRE_ALWAYS_INLINE QDataStream& operator<<(QDataStream &ds, - const SireUnits::Dimension::Unit &unit) +SIRE_ALWAYS_INLINE QDataStream &operator<<(QDataStream &ds, + const SireUnits::Dimension::Unit &unit) { ds << unit.sclfac; return ds; @@ -476,43 +493,49 @@ SIRE_ALWAYS_INLINE QDataStream& operator<<(QDataStream &ds, /** Extract from a binary datastream (this does not check the type of unit!) */ -SIRE_ALWAYS_INLINE QDataStream& operator>>(QDataStream &ds, - SireUnits::Dimension::Unit &unit) +SIRE_ALWAYS_INLINE QDataStream &operator>>(QDataStream &ds, + SireUnits::Dimension::Unit &unit) { ds >> unit.sclfac; return ds; } -Q_DECLARE_METATYPE( SireUnits::Dimension::Dimensionless ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Mass ); -Q_DECLARE_METATYPE( SireUnits::Dimension::MolarMass ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Length ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Time ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Charge ); -Q_DECLARE_METATYPE( SireUnits::Dimension::MolarCharge ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Temperature ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Quantity ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Angle ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Area ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Volume ); -Q_DECLARE_METATYPE( SireUnits::Dimension::MolarVolume ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Velocity ); -Q_DECLARE_METATYPE( SireUnits::Dimension::AngularVelocity ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Acceleration ); -Q_DECLARE_METATYPE( SireUnits::Dimension::AngularAcceleration ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Energy ); -Q_DECLARE_METATYPE( SireUnits::Dimension::MolarEnergy ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Power ); -Q_DECLARE_METATYPE( SireUnits::Dimension::MolarPower ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Density ); -Q_DECLARE_METATYPE( SireUnits::Dimension::MolarDensity ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Force ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Pressure ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Capacitance ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Current ); -Q_DECLARE_METATYPE( SireUnits::Dimension::Potential ); - -SIRE_EXPOSE_CLASS( SireUnits::Dimension::Unit ) +Q_DECLARE_METATYPE(SireUnits::Dimension::Dimensionless); +Q_DECLARE_METATYPE(SireUnits::Dimension::Mass); +Q_DECLARE_METATYPE(SireUnits::Dimension::MolarMass); +Q_DECLARE_METATYPE(SireUnits::Dimension::Length); +Q_DECLARE_METATYPE(SireUnits::Dimension::Time); +Q_DECLARE_METATYPE(SireUnits::Dimension::Charge); +Q_DECLARE_METATYPE(SireUnits::Dimension::MolarCharge); +Q_DECLARE_METATYPE(SireUnits::Dimension::Temperature); +Q_DECLARE_METATYPE(SireUnits::Dimension::Quantity); +Q_DECLARE_METATYPE(SireUnits::Dimension::Angle); +Q_DECLARE_METATYPE(SireUnits::Dimension::Area); +Q_DECLARE_METATYPE(SireUnits::Dimension::Volume); +Q_DECLARE_METATYPE(SireUnits::Dimension::MolarVolume); +Q_DECLARE_METATYPE(SireUnits::Dimension::Velocity); +Q_DECLARE_METATYPE(SireUnits::Dimension::AngularVelocity); +Q_DECLARE_METATYPE(SireUnits::Dimension::Acceleration); +Q_DECLARE_METATYPE(SireUnits::Dimension::AngularAcceleration); +Q_DECLARE_METATYPE(SireUnits::Dimension::Energy); +Q_DECLARE_METATYPE(SireUnits::Dimension::MolarEnergy); +Q_DECLARE_METATYPE(SireUnits::Dimension::Power); +Q_DECLARE_METATYPE(SireUnits::Dimension::MolarPower); +Q_DECLARE_METATYPE(SireUnits::Dimension::Density); +Q_DECLARE_METATYPE(SireUnits::Dimension::MolarDensity); +Q_DECLARE_METATYPE(SireUnits::Dimension::Force); +Q_DECLARE_METATYPE(SireUnits::Dimension::Pressure); +Q_DECLARE_METATYPE(SireUnits::Dimension::Capacitance); +Q_DECLARE_METATYPE(SireUnits::Dimension::Current); +Q_DECLARE_METATYPE(SireUnits::Dimension::Potential); + +Q_DECLARE_METATYPE(SireUnits::Dimension::Constant1); +Q_DECLARE_METATYPE(SireUnits::Dimension::Constant2); +Q_DECLARE_METATYPE(SireUnits::Dimension::Constant3); +Q_DECLARE_METATYPE(SireUnits::Dimension::Constant4); +Q_DECLARE_METATYPE(SireUnits::Dimension::Constant5); + +SIRE_EXPOSE_CLASS(SireUnits::Dimension::Unit) SIRE_END_HEADER diff --git a/corelib/src/libs/SireUnits/generalunit.cpp b/corelib/src/libs/SireUnits/generalunit.cpp index b3a5db21f..c4930c84b 100644 --- a/corelib/src/libs/SireUnits/generalunit.cpp +++ b/corelib/src/libs/SireUnits/generalunit.cpp @@ -22,7 +22,7 @@ using namespace SireStream; static const RegisterMetaType r_genunit(NO_ROOT); -QDataStream& operator<<(QDataStream &ds, const SireUnits::Dimension::GeneralUnit &u) +QDataStream &operator<<(QDataStream &ds, const SireUnits::Dimension::GeneralUnit &u) { writeHeader(ds, r_genunit, 1); @@ -38,12 +38,12 @@ QDataStream& operator<<(QDataStream &ds, const SireUnits::Dimension::GeneralUnit sds << u.comps << a << c << l << m << t1 << t2 << q - << static_cast(u); + << static_cast(u); return ds; } -QDataStream& operator>>(QDataStream &ds, SireUnits::Dimension::GeneralUnit &u) +QDataStream &operator>>(QDataStream &ds, SireUnits::Dimension::GeneralUnit &u) { VersionID v = readHeader(ds, r_genunit); @@ -53,9 +53,7 @@ QDataStream& operator>>(QDataStream &ds, SireUnits::Dimension::GeneralUnit &u) SharedDataStream sds(ds); - sds >> u.comps - >> a >> c >> l >> m >> t1 >> t2 >> q - >> static_cast(u); + sds >> u.comps >> a >> c >> l >> m >> t1 >> t2 >> q >> static_cast(u); u.Angle = a; u.Charge = c; @@ -73,50 +71,60 @@ QDataStream& operator>>(QDataStream &ds, SireUnits::Dimension::GeneralUnit &u) namespace SireUnits { -namespace Dimension -{ -namespace detail -{ - -static QHash typename_registry; -static QMutex registry_mutex; - -static QString getKey(const GeneralUnit &unit) -{ - return QString("%1-%2-%3-%4-%5-%6-%7") - .arg(unit.MASS()).arg(unit.LENGTH()).arg(unit.TIME()) - .arg(unit.CHARGE()).arg(unit.TEMPERATURE()) - .arg(unit.QUANTITY()).arg(unit.ANGLE()); -} - -void SIREUNITS_EXPORT registerTypeName(const GeneralUnit &unit, const char *typnam) -{ - QString key = getKey(unit); - - QMutexLocker lkr(®istry_mutex); - if (not typename_registry.contains(key)) + namespace Dimension { - typename_registry.insert( key, QString(typnam) ); - } -} - -static QString getTypeName(const GeneralUnit &unit) -{ - QString key = getKey(unit); - - QMutexLocker lkr(®istry_mutex); - - if (typename_registry.contains(key)) - return typename_registry.value(key); - else - return QString("SireUnits::Dimension::PhysUnit<%1,%2,%3,%4,%5,%6,%7>") - .arg(unit.MASS()).arg(unit.LENGTH()).arg(unit.TIME()) - .arg(unit.CHARGE()).arg(unit.TEMPERATURE()) - .arg(unit.QUANTITY()).arg(unit.ANGLE()); -} + namespace detail + { -} // end of namespace detail -} // end of namespace Dimension + typedef QHash TypenameRegistry; + + Q_GLOBAL_STATIC(TypenameRegistry, typename_registry); + Q_GLOBAL_STATIC(QMutex, registry_mutex); + + static QString getKey(const GeneralUnit &unit) + { + return QString("%1-%2-%3-%4-%5-%6-%7") + .arg(unit.MASS()) + .arg(unit.LENGTH()) + .arg(unit.TIME()) + .arg(unit.CHARGE()) + .arg(unit.TEMPERATURE()) + .arg(unit.QUANTITY()) + .arg(unit.ANGLE()); + } + + void SIREUNITS_EXPORT registerTypeName(const GeneralUnit &unit, const char *typnam) + { + QString key = getKey(unit); + + QMutexLocker lkr(registry_mutex()); + if (not typename_registry()->contains(key)) + { + typename_registry()->insert(key, QString(typnam)); + } + } + + static QString getTypeName(const GeneralUnit &unit) + { + QString key = getKey(unit); + + QMutexLocker lkr(registry_mutex()); + + if (typename_registry()->contains(key)) + return typename_registry()->value(key); + else + return QString("SireUnits::Dimension::PhysUnit<%1,%2,%3,%4,%5,%6,%7>") + .arg(unit.MASS()) + .arg(unit.LENGTH()) + .arg(unit.TIME()) + .arg(unit.CHARGE()) + .arg(unit.TEMPERATURE()) + .arg(unit.QUANTITY()) + .arg(unit.ANGLE()); + } + + } // end of namespace detail + } // end of namespace Dimension } // end of namespace SireUnits GeneralUnit::GeneralUnit() : Unit(0) @@ -153,7 +161,7 @@ GeneralUnit::GeneralUnit(const TempBase &t) : Unit(t) } GeneralUnit::GeneralUnit(const GeneralUnit &other) - : Unit(other), comps(other.comps) + : Unit(other), comps(other.comps) { Mass = other.Mass; Length = other.Length; @@ -165,14 +173,15 @@ GeneralUnit::GeneralUnit(const GeneralUnit &other) } GeneralUnit::~GeneralUnit() -{} +{ +} -const char* GeneralUnit::typeName() +const char *GeneralUnit::typeName() { - return QMetaType::typeName( qMetaTypeId() ); + return QMetaType::typeName(qMetaTypeId()); } -const char* GeneralUnit::what() const +const char *GeneralUnit::what() const { return GeneralUnit::typeName(); } @@ -196,9 +205,10 @@ void GeneralUnit::assertCompatible(const GeneralUnit &other) const Quantity != other.Quantity or Angle != other.Angle) { - throw SireError::incompatible_error( QObject::tr( - "Units for values %1 and %2 are incompatible.") - .arg(this->toString()).arg(other.toString())); + throw SireError::incompatible_error(QObject::tr( + "Units for values %1 and %2 are incompatible.") + .arg(this->toString()) + .arg(other.toString())); } } @@ -207,7 +217,8 @@ QString GeneralUnit::unitString() const return SireUnits::Dimension::getUnitString(Mass, Length, Time, Charge, temperature, Quantity, - Angle).second; + Angle) + .second; } QString GeneralUnit::toString() const @@ -236,7 +247,7 @@ double GeneralUnit::to(const GeneralUnit &units) const double GeneralUnit::to(const TempBase &other) const { - //this must be a temperature! + // this must be a temperature! GeneralUnit general_temp; general_temp.temperature = 1; general_temp.setScale(other); @@ -321,7 +332,7 @@ bool GeneralUnit::hasSameUnits(const GeneralUnit &other) const Angle == other.Angle; } -GeneralUnit& GeneralUnit::operator=(const GeneralUnit &other) +GeneralUnit &GeneralUnit::operator=(const GeneralUnit &other) { setScale(other.value()); @@ -380,7 +391,7 @@ bool GeneralUnit::operator<=(const GeneralUnit &other) const GeneralUnit GeneralUnit::operator-() const { GeneralUnit ret = *this; - ret.setScale( -value() ); + ret.setScale(-value()); for (const auto &key : this->comps.keys()) { @@ -390,7 +401,47 @@ GeneralUnit GeneralUnit::operator-() const return ret; } -GeneralUnit& GeneralUnit::operator+=(const GeneralUnit &other) +GeneralUnit &GeneralUnit::operator+=(const TempBase &other) +{ + return this->operator+=(GeneralUnit(other)); +} + +GeneralUnit &GeneralUnit::operator-=(const TempBase &other) +{ + return this->operator-=(GeneralUnit(other)); +} + +GeneralUnit &GeneralUnit::operator*=(const TempBase &other) +{ + return this->operator*=(GeneralUnit(other)); +} + +GeneralUnit &GeneralUnit::operator/=(const TempBase &other) +{ + return this->operator/=(GeneralUnit(other)); +} + +GeneralUnit GeneralUnit::operator+(const TempBase &other) const +{ + return this->operator+(GeneralUnit(other)); +} + +GeneralUnit GeneralUnit::operator-(const TempBase &other) const +{ + return this->operator-(GeneralUnit(other)); +} + +GeneralUnit GeneralUnit::operator*(const TempBase &other) const +{ + return this->operator*(GeneralUnit(other)); +} + +GeneralUnit GeneralUnit::operator/(const TempBase &other) const +{ + return this->operator/(GeneralUnit(other)); +} + +GeneralUnit &GeneralUnit::operator+=(const GeneralUnit &other) { if (this->isZero()) { @@ -417,7 +468,7 @@ GeneralUnit& GeneralUnit::operator+=(const GeneralUnit &other) return *this; } -GeneralUnit& GeneralUnit::operator-=(const GeneralUnit &other) +GeneralUnit &GeneralUnit::operator-=(const GeneralUnit &other) { if (this->isZero()) { @@ -458,7 +509,7 @@ GeneralUnit GeneralUnit::operator-(const GeneralUnit &other) const return ret; } -GeneralUnit& GeneralUnit::operator+=(double val) +GeneralUnit &GeneralUnit::operator+=(double val) { assertCompatible(GeneralUnit(val)); setScale(value() + val); @@ -469,7 +520,7 @@ GeneralUnit& GeneralUnit::operator+=(double val) return *this; } -GeneralUnit& GeneralUnit::operator-=(double val) +GeneralUnit &GeneralUnit::operator-=(double val) { assertCompatible(GeneralUnit(val)); setScale(value() - val); @@ -494,7 +545,7 @@ GeneralUnit GeneralUnit::operator-(double val) const return ret; } -GeneralUnit GeneralUnit::operator*=(const GeneralUnit &other) +GeneralUnit &GeneralUnit::operator*=(const GeneralUnit &other) { setScale(value() * other.value()); Mass += other.Mass; @@ -543,7 +594,7 @@ GeneralUnit GeneralUnit::operator*=(const GeneralUnit &other) return *this; } -GeneralUnit GeneralUnit::operator/=(const GeneralUnit &other) +GeneralUnit &GeneralUnit::operator/=(const GeneralUnit &other) { setScale(value() / other.value()); Mass -= other.Mass; @@ -592,6 +643,46 @@ GeneralUnit GeneralUnit::operator/=(const GeneralUnit &other) return *this; } +SIREUNITS_EXPORT GeneralUnit Celsius::operator+(const GeneralUnit &other) const +{ + return other.operator+(*this); +} + +SIREUNITS_EXPORT GeneralUnit Celsius::operator-(const GeneralUnit &other) const +{ + return GeneralUnit(*this) - other; +} + +SIREUNITS_EXPORT GeneralUnit Celsius::operator*(const GeneralUnit &other) const +{ + return other.operator*(*this); +} + +SIREUNITS_EXPORT GeneralUnit Celsius::operator/(const GeneralUnit &other) const +{ + return GeneralUnit(*this) / other; +} + +SIREUNITS_EXPORT GeneralUnit Fahrenheit::operator+(const GeneralUnit &other) const +{ + return other.operator+(*this); +} + +SIREUNITS_EXPORT GeneralUnit Fahrenheit::operator-(const GeneralUnit &other) const +{ + return GeneralUnit(*this) - other; +} + +SIREUNITS_EXPORT GeneralUnit Fahrenheit::operator*(const GeneralUnit &other) const +{ + return other.operator*(*this); +} + +SIREUNITS_EXPORT GeneralUnit Fahrenheit::operator/(const GeneralUnit &other) const +{ + return GeneralUnit(*this) / other; +} + GeneralUnit GeneralUnit::operator*(const GeneralUnit &other) const { GeneralUnit ret = *this; @@ -607,7 +698,7 @@ GeneralUnit GeneralUnit::operator/(const GeneralUnit &other) const return ret; } -GeneralUnit& GeneralUnit::operator*=(double val) +GeneralUnit &GeneralUnit::operator*=(double val) { setScale(value() * val); @@ -625,7 +716,7 @@ GeneralUnit& GeneralUnit::operator*=(double val) return *this; } -GeneralUnit& GeneralUnit::operator/=(double val) +GeneralUnit &GeneralUnit::operator/=(double val) { setScale(value() / val); @@ -643,12 +734,12 @@ GeneralUnit& GeneralUnit::operator/=(double val) return *this; } -GeneralUnit& GeneralUnit::operator*=(int val) +GeneralUnit &GeneralUnit::operator*=(int val) { return this->operator*=(double(val)); } -GeneralUnit& GeneralUnit::operator/=(int val) +GeneralUnit &GeneralUnit::operator/=(int val) { return this->operator/=(double(val)); } @@ -685,7 +776,7 @@ GeneralUnit GeneralUnit::invert() const { GeneralUnit ret; - ret.setScale( 1.0 / value() ); + ret.setScale(1.0 / value()); ret.Mass = -Mass; ret.Length = -Length; @@ -701,15 +792,15 @@ GeneralUnit GeneralUnit::invert() const return ret; } -QHash GeneralUnit::components() const +QHash GeneralUnit::components() const { - QHash c; + QHash c; c.reserve(this->comps.count()); for (const auto &key : this->comps.keys()) { GeneralUnit v(*this); - v.comps = QHash(); + v.comps = QHash(); v.setScale(this->comps[key]); c.insert(key, v); } @@ -720,7 +811,7 @@ QHash GeneralUnit::components() const GeneralUnit GeneralUnit::getComponent(const QString &component) const { GeneralUnit v(*this); - v.comps = QHash(); + v.comps = QHash(); v.setScale(this->comps.value(component)); return v; } diff --git a/corelib/src/libs/SireUnits/generalunit.h b/corelib/src/libs/SireUnits/generalunit.h index d076b157f..d9384db94 100644 --- a/corelib/src/libs/SireUnits/generalunit.h +++ b/corelib/src/libs/SireUnits/generalunit.h @@ -8,261 +8,274 @@ SIRE_BEGIN_HEADER -namespace SireUnits{ namespace Dimension { -class GeneralUnit; -}} - -SIREUNITS_EXPORT QDataStream& operator<<(QDataStream&, const SireUnits::Dimension::GeneralUnit&); -SIREUNITS_EXPORT QDataStream& operator>>(QDataStream&, SireUnits::Dimension::GeneralUnit&); - namespace SireUnits { - -namespace Dimension -{ - -class GeneralUnit; -class TempBase; -class _Pvt_Kelvin; - -namespace detail -{ -void SIREUNITS_EXPORT registerTypeName(const GeneralUnit &unit, const char *typnam); + namespace Dimension + { + class GeneralUnit; + } } -class SIREUNITS_EXPORT GeneralUnit : public Unit -{ - -friend QDataStream& ::operator<<(QDataStream&, const GeneralUnit&); -friend QDataStream& ::operator>>(QDataStream&, GeneralUnit&); - -public: - GeneralUnit(); - - explicit GeneralUnit(const TempBase &temperature); +SIREUNITS_EXPORT QDataStream &operator<<(QDataStream &, const SireUnits::Dimension::GeneralUnit &); +SIREUNITS_EXPORT QDataStream &operator>>(QDataStream &, SireUnits::Dimension::GeneralUnit &); - explicit GeneralUnit(double value); +namespace SireUnits +{ - template - explicit GeneralUnit(const PhysUnit &unit) : Unit(unit) + namespace Dimension { - Mass = M; - Length = L; - Time = T; - Charge = C; - temperature = t; - Quantity = Q; - Angle = A; - detail::registerTypeName(*this, PhysUnit::typeName()); - - if (this->isZero()) - this->operator=(GeneralUnit()); - } - GeneralUnit(const GeneralUnit &other); + class GeneralUnit; + class TempBase; + class _Pvt_Kelvin; - ~GeneralUnit(); + namespace detail + { + void SIREUNITS_EXPORT registerTypeName(const GeneralUnit &unit, const char *typnam); + } - static const char* typeName(); - const char* what() const; + class SIREUNITS_EXPORT GeneralUnit : public Unit + { - QString _to_cpp_type() const; + friend QDataStream & ::operator<<(QDataStream &, const GeneralUnit &); + friend QDataStream & ::operator>>(QDataStream &, GeneralUnit &); - QString unitString() const; + public: + GeneralUnit(); - GeneralUnit units() const; + explicit GeneralUnit(const TempBase &temperature); - int MASS() const; - int LENGTH() const; - int TIME() const; - int CHARGE() const; - int TEMPERATURE() const; - int QUANTITY() const; - int ANGLE() const; + explicit GeneralUnit(double value); - bool hasSameUnits(const GeneralUnit &other) const; + template + explicit GeneralUnit(const PhysUnit &unit) : Unit(unit) + { + Mass = M; + Length = L; + Time = T; + Charge = C; + temperature = t; + Quantity = Q; + Angle = A; + detail::registerTypeName(*this, PhysUnit::typeName()); - GeneralUnit& operator=(const GeneralUnit &other); + if (this->isZero()) + this->operator=(GeneralUnit()); + } - bool operator==(const GeneralUnit &other) const; - bool operator!=(const GeneralUnit &other) const; + GeneralUnit(const GeneralUnit &other); - bool operator>(const GeneralUnit &other) const; - bool operator>=(const GeneralUnit &other) const; - bool operator<(const GeneralUnit &other) const; - bool operator<=(const GeneralUnit &other) const; + ~GeneralUnit(); - GeneralUnit operator-() const; + static const char *typeName(); + const char *what() const; - GeneralUnit& operator+=(const GeneralUnit &other); + QString _to_cpp_type() const; - GeneralUnit& operator-=(const GeneralUnit &other); + QString unitString() const; - GeneralUnit operator+(const GeneralUnit &other) const; + GeneralUnit units() const; - GeneralUnit operator-(const GeneralUnit &other) const; + int MASS() const; + int LENGTH() const; + int TIME() const; + int CHARGE() const; + int TEMPERATURE() const; + int QUANTITY() const; + int ANGLE() const; - GeneralUnit operator*=(const GeneralUnit &other); + bool hasSameUnits(const GeneralUnit &other) const; - GeneralUnit operator/=(const GeneralUnit &other); + GeneralUnit &operator=(const GeneralUnit &other); - GeneralUnit operator*(const GeneralUnit &other) const; + bool operator==(const GeneralUnit &other) const; + bool operator!=(const GeneralUnit &other) const; - GeneralUnit operator/(const GeneralUnit &other) const; + bool operator>(const GeneralUnit &other) const; + bool operator>=(const GeneralUnit &other) const; + bool operator<(const GeneralUnit &other) const; + bool operator<=(const GeneralUnit &other) const; - GeneralUnit& operator+=(double val); - GeneralUnit& operator-=(double val); + GeneralUnit operator-() const; - GeneralUnit operator+(double val) const; - GeneralUnit operator-(double val) const; + GeneralUnit &operator+=(const GeneralUnit &other); + GeneralUnit &operator+=(const TempBase &other); - GeneralUnit& operator*=(double val); - GeneralUnit& operator/=(double val); + GeneralUnit &operator-=(const GeneralUnit &other); + GeneralUnit &operator-=(const TempBase &other); - GeneralUnit& operator*=(int val); - GeneralUnit& operator/=(int val); + GeneralUnit operator+(const GeneralUnit &other) const; + GeneralUnit operator+(const TempBase &other) const; - GeneralUnit operator*(double val) const; - GeneralUnit operator/(double val) const; + GeneralUnit operator-(const GeneralUnit &other) const; + GeneralUnit operator-(const TempBase &other) const; - GeneralUnit operator*(int val) const; - GeneralUnit operator/(int val) const; + GeneralUnit &operator*=(const GeneralUnit &other); + GeneralUnit &operator*=(const TempBase &other); - GeneralUnit invert() const; + GeneralUnit &operator/=(const GeneralUnit &other); + GeneralUnit &operator/=(const TempBase &other); - double to(const TempBase &other) const; - double to(const GeneralUnit &other) const; + GeneralUnit operator*(const GeneralUnit &other) const; + GeneralUnit operator*(const TempBase &other) const; - QString toString() const; + GeneralUnit operator/(const GeneralUnit &other) const; + GeneralUnit operator/(const TempBase &other) const; - template - bool isUnit() const; + GeneralUnit &operator+=(double val); + GeneralUnit &operator-=(double val); - template - T toUnit() const; + GeneralUnit operator+(double val) const; + GeneralUnit operator-(double val) const; - bool isDimensionless() const; + GeneralUnit &operator*=(double val); + GeneralUnit &operator/=(double val); - bool isZero() const; + GeneralUnit &operator*=(int val); + GeneralUnit &operator/=(int val); - void setAsDefault(const QString &unit_name) const; + GeneralUnit operator*(double val) const; + GeneralUnit operator/(double val) const; - GeneralUnit getDefault() const; + GeneralUnit operator*(int val) const; + GeneralUnit operator/(int val) const; - QHash components() const; + GeneralUnit invert() const; - GeneralUnit getComponent(const QString &component) const; + double to(const TempBase &other) const; + double to(const GeneralUnit &other) const; - void setComponent(const QString &component, - const GeneralUnit &value); + QString toString() const; - void addComponent(const QString &component, - const GeneralUnit &value); + template + bool isUnit() const; - void subtractComponent(const QString &component, - const GeneralUnit &value); + template + T toUnit() const; - template - void setComponent(const QString &component, - const PhysUnit &value) - { - this->setComponent(component, GeneralUnit(value)); - } + bool isDimensionless() const; - template - void addComponent(const QString &component, - const PhysUnit &value) - { - this->addComponent(component, GeneralUnit(value)); - } + bool isZero() const; - template - void subtractComponent(const QString &component, - const PhysUnit &value) - { - this->subtractComponent(component, GeneralUnit(value)); - } + void setAsDefault(const QString &unit_name) const; -private: - void assertCompatible(const GeneralUnit &other) const; + GeneralUnit getDefault() const; - int Mass, Length, Time, Charge, temperature, Quantity, Angle; + QHash components() const; - QHash comps; -}; + GeneralUnit getComponent(const QString &component) const; -#ifndef SIRE_SKIP_INLINE_FUNCTIONS + void setComponent(const QString &component, + const GeneralUnit &value); -template -inline bool GeneralUnit::isUnit() const -{ - return this->MASS() == T::MASS() and - this->LENGTH() == T::LENGTH() and - this->TIME() == T::TIME() and - this->CHARGE() == T::CHARGE() and - this->TEMPERATURE() == T::TEMPERATURE() and - this->QUANTITY() == T::QUANTITY() and - this->ANGLE() == T::ANGLE(); -} + void addComponent(const QString &component, + const GeneralUnit &value); -template -inline T GeneralUnit::toUnit() const -{ - this->assertCompatible(GeneralUnit(T(1.0))); - return this->scaleFactor() * T(1.0); -} + void subtractComponent(const QString &component, + const GeneralUnit &value); -inline GeneralUnit operator*(double val, const GeneralUnit &unit) -{ - return unit * val; -} + template + void setComponent(const QString &component, + const PhysUnit &value) + { + this->setComponent(component, GeneralUnit(value)); + } -inline GeneralUnit operator*(int val, const GeneralUnit &unit) -{ - return unit * val; -} + template + void addComponent(const QString &component, + const PhysUnit &value) + { + this->addComponent(component, GeneralUnit(value)); + } -inline GeneralUnit operator/(double val, const GeneralUnit &unit) -{ - return unit.invert() * val; -} + template + void subtractComponent(const QString &component, + const PhysUnit &value) + { + this->subtractComponent(component, GeneralUnit(value)); + } -inline GeneralUnit operator/(int val, const GeneralUnit &unit) -{ - return unit.invert() * val; -} + private: + void assertCompatible(const GeneralUnit &other) const; -template -SIRE_OUTOFLINE_TEMPLATE -PhysUnit& PhysUnit::operator=(const GeneralUnit &other) -{ - this->operator=(other.toUnit>()); - return *this; -} + int Mass, Length, Time, Charge, temperature, Quantity, Angle; -template -SIRE_OUTOFLINE_TEMPLATE -PhysUnit::PhysUnit(const GeneralUnit &other) - : Unit(0) -{ - this->operator=(other); -} + QHash comps; + }; -#endif //SIRE_SKIP_INLINE_FUNCTIONS +#ifndef SIRE_SKIP_INLINE_FUNCTIONS -} // end of namespace Dimension + template + inline bool GeneralUnit::isUnit() const + { + return this->MASS() == T::MASS() and + this->LENGTH() == T::LENGTH() and + this->TIME() == T::TIME() and + this->CHARGE() == T::CHARGE() and + this->TEMPERATURE() == T::TEMPERATURE() and + this->QUANTITY() == T::QUANTITY() and + this->ANGLE() == T::ANGLE(); + } + + template + inline T GeneralUnit::toUnit() const + { + this->assertCompatible(GeneralUnit(T(1.0))); + return this->scaleFactor() * T(1.0); + } + + inline GeneralUnit operator*(double val, const GeneralUnit &unit) + { + return unit * val; + } + + inline GeneralUnit operator*(int val, const GeneralUnit &unit) + { + return unit * val; + } + + inline GeneralUnit operator/(double val, const GeneralUnit &unit) + { + return unit.invert() * val; + } + + inline GeneralUnit operator/(int val, const GeneralUnit &unit) + { + return unit.invert() * val; + } + + template + SIRE_OUTOFLINE_TEMPLATE + PhysUnit & + PhysUnit::operator=(const GeneralUnit &other) + { + this->operator=(other.toUnit>()); + return *this; + } + + template + SIRE_OUTOFLINE_TEMPLATE + PhysUnit::PhysUnit(const GeneralUnit &other) + : Unit(0) + { + this->operator=(other); + } + +#endif // SIRE_SKIP_INLINE_FUNCTIONS + + } // end of namespace Dimension } -Q_DECLARE_METATYPE( SireUnits::Dimension::GeneralUnit ); +Q_DECLARE_METATYPE(SireUnits::Dimension::GeneralUnit); -SIRE_EXPOSE_CLASS( SireUnits::Dimension::GeneralUnit ) +SIRE_EXPOSE_CLASS(SireUnits::Dimension::GeneralUnit) SIRE_END_HEADER diff --git a/corelib/src/libs/SireUnits/temperature.h b/corelib/src/libs/SireUnits/temperature.h index e95b0300f..2e9f8ac02 100644 --- a/corelib/src/libs/SireUnits/temperature.h +++ b/corelib/src/libs/SireUnits/temperature.h @@ -35,444 +35,471 @@ SIRE_BEGIN_HEADER namespace SireUnits { -class Celsius; -class Fahrenheit; + class Celsius; + class Fahrenheit; -namespace Dimension -{ - -//skip this completely when parsing with gccxml as it is broken! -#ifdef SKIP_BROKEN_GCCXML_PARTS - -class Temperature -{ -public: - Temperature(); - Temperature(double); - ~Temperature(); - - operator double() const; -}; - -#endif // end of 'ifdef SKIP_BROKEN_GCCXML_PARTS' - -class TempBase -{ -friend class SireUnits::Celsius; -friend class SireUnits::Fahrenheit; - -public: - TempBase(double value = 0) : val(value) - {} - - TempBase(const TempBase &other) : val(other.val) - {} - - TempBase(const Temperature &temp) : val(temp) - {} - - virtual ~TempBase() - {} - - TempBase& operator=(const TempBase &other) - { - val = other.val; - return *this; - } - - TempBase& operator=(const Temperature &temp) - { - val = double(temp); - return *this; - } - - bool operator==(const TempBase &other) const - { - return val == other.val; - } - - bool operator!=(const TempBase &other) const - { - return val != other.val; - } - - bool operator==(const Temperature &temp) const + namespace Dimension { - return val == double(temp); - } - bool operator!=(const Temperature &temp) const - { - return val != double(temp); - } - - double value() const - { - return val; - } - - QString toString() const - { - return QString("%1°%2").arg(this->convertFromInternal()).arg(this->unitString()); - } - - /** Convert this into a temperature object */ - operator Temperature() const - { - return Temperature(val); - } - - operator double() const - { - return val; - } - - double in(const TempBase &other) const - { - return other.convertFromInternal(val) / other.convertFromInternal(); - } - - double in(const Temperature &temp) const - { - return val * temp; - } - - double to(const TempBase &other) const - { - return this->in(other); - } + class GeneralUnit; - virtual double convertToInternal(double value) const=0; - virtual double convertFromInternal(double value) const=0; +// skip this completely when parsing with gccxml as it is broken! +#ifdef SKIP_BROKEN_GCCXML_PARTS - double convertFromInternal() const - { - return this->convertFromInternal(val); - } + class Temperature + { + public: + Temperature(); + Temperature(double); + ~Temperature(); -protected: - virtual QString unitString() const - { - return "K"; - } + operator double() const; + }; - /** This holds the temperature in internal units (K) */ - double val; -}; +#endif // end of 'ifdef SKIP_BROKEN_GCCXML_PARTS' -/** Construct a Unit from a TempBase */ -SIRE_ALWAYS_INLINE Unit::Unit(const TempBase &temperature) + class TempBase + { + friend class SireUnits::Celsius; + friend class SireUnits::Fahrenheit; + + public: + TempBase(double value = 0) : val(value) + { + } + + TempBase(const TempBase &other) : val(other.val) + { + } + + TempBase(const Temperature &temp) : val(temp) + { + } + + virtual ~TempBase() + { + } + + TempBase &operator=(const TempBase &other) + { + val = other.val; + return *this; + } + + TempBase &operator=(const Temperature &temp) + { + val = double(temp); + return *this; + } + + bool operator==(const TempBase &other) const + { + return val == other.val; + } + + bool operator!=(const TempBase &other) const + { + return val != other.val; + } + + bool operator==(const Temperature &temp) const + { + return val == double(temp); + } + + bool operator!=(const Temperature &temp) const + { + return val != double(temp); + } + + double value() const + { + return val; + } + + QString toString() const + { + return QString("%1°%2").arg(this->convertFromInternal()).arg(this->unitString()); + } + + /** Convert this into a temperature object */ + operator Temperature() const + { + return Temperature(val); + } + + operator double() const + { + return val; + } + + double in(const TempBase &other) const + { + return other.convertFromInternal(val) / other.convertFromInternal(); + } + + double in(const Temperature &temp) const + { + return val * temp; + } + + double to(const TempBase &other) const + { + return this->in(other); + } + + virtual double convertToInternal(double value) const = 0; + virtual double convertFromInternal(double value) const = 0; + + double convertFromInternal() const + { + return this->convertFromInternal(val); + } + + protected: + virtual QString unitString() const + { + return "K"; + } + + /** This holds the temperature in internal units (K) */ + double val; + }; + + /** Construct a Unit from a TempBase */ + SIRE_ALWAYS_INLINE Unit::Unit(const TempBase &temperature) : sclfac(temperature) -{} - -} //end of namespace Dimension - -class Celsius : public Dimension::TempBase -{ - -public: - Celsius() : Dimension::TempBase(1) - {} - - explicit Celsius(double value) : Dimension::TempBase() - { - val = convertToInternal(value); - } - - Celsius(const Dimension::Temperature &temp) : Dimension::TempBase(temp) - {} - - Celsius(const Dimension::TempBase &other) : Dimension::TempBase(other) - {} - - Celsius(const Celsius &other) - : Dimension::TempBase(other) - {} - - ~Celsius() - {} - - double convertToInternal(double value) const - { - return value + 273.15; - } - - double convertFromInternal(double value) const - { - return value - 273.15; - } - - double convertFromInternal() const - { - return Dimension::TempBase::convertFromInternal(); - } - - Celsius& operator=(const Celsius &other) - { - Dimension::TempBase::operator=(other); - return *this; - } - - Celsius& operator=(const Dimension::Temperature &temp) - { - Dimension::TempBase::operator=(temp); - return *this; - } - - Celsius operator-() const - { - return Celsius(-convertFromInternal()); - } - - Celsius operator+(const Celsius &other) const - { - return Celsius(convertFromInternal() + other.convertFromInternal()); - } - - Celsius operator-(const Celsius &other) const - { - return Celsius(convertFromInternal() - other.convertFromInternal()); - } - - Celsius& operator+=(const Celsius &other) - { - convertToInternal( convertFromInternal() + other.convertFromInternal() ); - return *this; - } - - Celsius& operator-=(const Celsius &other) - { - convertToInternal( convertFromInternal() - other.convertFromInternal() ); - return *this; - } - - Celsius operator+(const Dimension::Temperature &other) const - { - return *this + Celsius(other); + { + } + + } // end of namespace Dimension + + class Celsius : public Dimension::TempBase + { + + public: + Celsius() : Dimension::TempBase(1) + { + } + + explicit Celsius(double value) : Dimension::TempBase() + { + val = convertToInternal(value); + } + + Celsius(const Dimension::Temperature &temp) : Dimension::TempBase(temp) + { + } + + Celsius(const Dimension::TempBase &other) : Dimension::TempBase(other) + { + } + + Celsius(const Celsius &other) + : Dimension::TempBase(other) + { + } + + ~Celsius() + { + } + + double convertToInternal(double value) const + { + return value + 273.15; + } + + double convertFromInternal(double value) const + { + return value - 273.15; + } + + double convertFromInternal() const + { + return Dimension::TempBase::convertFromInternal(); + } + + Celsius &operator=(const Celsius &other) + { + Dimension::TempBase::operator=(other); + return *this; + } + + Celsius &operator=(const Dimension::Temperature &temp) + { + Dimension::TempBase::operator=(temp); + return *this; + } + + Celsius operator-() const + { + return Celsius(-convertFromInternal()); + } + + Celsius operator+(const Celsius &other) const + { + return Celsius(convertFromInternal() + other.convertFromInternal()); + } + + Celsius operator-(const Celsius &other) const + { + return Celsius(convertFromInternal() - other.convertFromInternal()); + } + + Celsius &operator+=(const Celsius &other) + { + convertToInternal(convertFromInternal() + other.convertFromInternal()); + return *this; + } + + Celsius &operator-=(const Celsius &other) + { + convertToInternal(convertFromInternal() - other.convertFromInternal()); + return *this; + } + + Celsius operator+(const Dimension::Temperature &other) const + { + return *this + Celsius(other); + } + + Celsius operator-(const Dimension::Temperature &other) const + { + return *this - Celsius(other); + } + + Celsius &operator+=(const Dimension::Temperature &other) + { + return this->operator+=(Celsius(other)); + } + + Celsius &operator-=(const Dimension::Temperature &other) + { + return this->operator-=(Celsius(other)); + } + + Celsius operator*(double value) const + { + return Celsius(value * convertFromInternal()); + } + + Celsius operator/(double value) const + { + return Celsius(value / convertFromInternal()); + } + + Celsius operator*(int value) const + { + return Celsius(value * convertFromInternal()); + } + + Celsius operator/(int value) const + { + return Celsius(value / convertFromInternal()); + } + + SIREUNITS_EXPORT Dimension::GeneralUnit operator+(const Dimension::GeneralUnit &other) const; + SIREUNITS_EXPORT Dimension::GeneralUnit operator-(const Dimension::GeneralUnit &other) const; + SIREUNITS_EXPORT Dimension::GeneralUnit operator*(const Dimension::GeneralUnit &other) const; + SIREUNITS_EXPORT Dimension::GeneralUnit operator/(const Dimension::GeneralUnit &other) const; + + protected: + QString unitString() const + { + return "C"; + } + }; + + SIRE_ALWAYS_INLINE Celsius operator*(double value, const Celsius &temp) + { + return temp * value; } - Celsius operator-(const Dimension::Temperature &other) const - { - return *this - Celsius(other); - } - - Celsius& operator+=(const Dimension::Temperature &other) - { - return this->operator+=(Celsius(other)); - } - - Celsius& operator-=(const Dimension::Temperature &other) - { - return this->operator-=(Celsius(other)); - } - - Celsius operator*(double value) const - { - return Celsius(value * convertFromInternal()); - } - - Celsius operator/(double value) const - { - return Celsius(value / convertFromInternal()); - } - - Celsius operator*(int value) const - { - return Celsius(value * convertFromInternal()); - } - - Celsius operator/(int value) const - { - return Celsius(value / convertFromInternal()); - } - -protected: - QString unitString() const - { - return "C"; - } -}; - -SIRE_ALWAYS_INLINE Celsius operator*(double value, const Celsius &temp) -{ - return temp * value; -} - #ifndef SKIP_BROKEN_GCCXML_PARTS -SIRE_ALWAYS_INLINE Dimension::PhysUnit<0,0,0,0,-1,0,0> operator/(double value, const Celsius &temp) -{ - return Dimension::PhysUnit<0,0,0,0,-1,0,0>(value / temp.convertFromInternal()); -} - -SIRE_ALWAYS_INLINE Dimension::PhysUnit<0,0,0,0,-1,0,0> operator/(int value, const Celsius &temp) -{ - return Dimension::PhysUnit<0,0,0,0,-1,0,0>(value / temp.convertFromInternal()); -} -#endif - -SIRE_ALWAYS_INLINE Celsius operator*(int value, const Celsius &temp) -{ - return temp * value; -} - -class Fahrenheit : public Dimension::TempBase -{ - -public: - Fahrenheit() : Dimension::TempBase(1) - {} - - explicit Fahrenheit(double value) : Dimension::TempBase() - { - val = convertToInternal(value); - } - - Fahrenheit(const Dimension::Temperature &temp) : Dimension::TempBase(temp) - {} - - Fahrenheit(const Dimension::TempBase &other) : Dimension::TempBase(other) - {} - - Fahrenheit(const Fahrenheit &other) - : Dimension::TempBase(other) - {} - - ~Fahrenheit() - {} - - double convertToInternal(double value) const - { - return (value + 459.67) / 1.8; - } - - double convertFromInternal(double value) const + SIRE_ALWAYS_INLINE Dimension::PhysUnit<0, 0, 0, 0, -1, 0, 0> operator/(double value, const Celsius &temp) { - return (value * 1.8) - 459.67; + return Dimension::PhysUnit<0, 0, 0, 0, -1, 0, 0>(value / temp.convertFromInternal()); } - double convertFromInternal() const + SIRE_ALWAYS_INLINE Dimension::PhysUnit<0, 0, 0, 0, -1, 0, 0> operator/(int value, const Celsius &temp) { - return Dimension::TempBase::convertFromInternal(); - } - - Fahrenheit& operator=(const Fahrenheit &other) - { - Dimension::TempBase::operator=(other); - return *this; - } - - Fahrenheit& operator=(const Dimension::Temperature &temp) - { - Dimension::TempBase::operator=(temp); - return *this; - } - - Fahrenheit operator-() const - { - return Fahrenheit(-convertFromInternal()); - } - - Fahrenheit operator+(const Fahrenheit &other) const - { - return Fahrenheit(convertFromInternal() + other.convertFromInternal()); - } - - Fahrenheit operator-(const Fahrenheit &other) const - { - return Fahrenheit(convertFromInternal() - other.convertFromInternal()); - } - - Fahrenheit& operator+=(const Fahrenheit &other) - { - convertToInternal( convertFromInternal() + other.convertFromInternal() ); - return *this; - } - - Fahrenheit& operator-=(const Fahrenheit &other) - { - convertToInternal( convertFromInternal() - other.convertFromInternal() ); - return *this; - } - - Fahrenheit operator+(const Dimension::Temperature &other) const - { - return *this + Fahrenheit(other); - } - - Fahrenheit operator-(const Dimension::Temperature &other) const - { - return *this - Fahrenheit(other); + return Dimension::PhysUnit<0, 0, 0, 0, -1, 0, 0>(value / temp.convertFromInternal()); } +#endif - Fahrenheit& operator+=(const Dimension::Temperature &other) - { - return this->operator+=(Fahrenheit(other)); - } + SIRE_ALWAYS_INLINE Celsius operator*(int value, const Celsius &temp) + { + return temp * value; + } + + class Fahrenheit : public Dimension::TempBase + { + + public: + Fahrenheit() : Dimension::TempBase(1) + { + } + + explicit Fahrenheit(double value) : Dimension::TempBase() + { + val = convertToInternal(value); + } + + Fahrenheit(const Dimension::Temperature &temp) : Dimension::TempBase(temp) + { + } + + Fahrenheit(const Dimension::TempBase &other) : Dimension::TempBase(other) + { + } + + Fahrenheit(const Fahrenheit &other) + : Dimension::TempBase(other) + { + } + + ~Fahrenheit() + { + } + + double convertToInternal(double value) const + { + return (value + 459.67) / 1.8; + } + + double convertFromInternal(double value) const + { + return (value * 1.8) - 459.67; + } + + double convertFromInternal() const + { + return Dimension::TempBase::convertFromInternal(); + } + + Fahrenheit &operator=(const Fahrenheit &other) + { + Dimension::TempBase::operator=(other); + return *this; + } + + Fahrenheit &operator=(const Dimension::Temperature &temp) + { + Dimension::TempBase::operator=(temp); + return *this; + } + + Fahrenheit operator-() const + { + return Fahrenheit(-convertFromInternal()); + } + + Fahrenheit operator+(const Fahrenheit &other) const + { + return Fahrenheit(convertFromInternal() + other.convertFromInternal()); + } + + Fahrenheit operator-(const Fahrenheit &other) const + { + return Fahrenheit(convertFromInternal() - other.convertFromInternal()); + } + + Fahrenheit &operator+=(const Fahrenheit &other) + { + convertToInternal(convertFromInternal() + other.convertFromInternal()); + return *this; + } + + Fahrenheit &operator-=(const Fahrenheit &other) + { + convertToInternal(convertFromInternal() - other.convertFromInternal()); + return *this; + } + + Fahrenheit operator+(const Dimension::Temperature &other) const + { + return *this + Fahrenheit(other); + } + + Fahrenheit operator-(const Dimension::Temperature &other) const + { + return *this - Fahrenheit(other); + } + + Fahrenheit &operator+=(const Dimension::Temperature &other) + { + return this->operator+=(Fahrenheit(other)); + } + + Fahrenheit &operator-=(const Dimension::Temperature &other) + { + return this->operator-=(Fahrenheit(other)); + } + + Fahrenheit operator*(double value) const + { + return Fahrenheit(value * convertFromInternal()); + } + + Fahrenheit operator/(double value) const + { + return Fahrenheit(value / convertFromInternal()); + } + + Fahrenheit operator*(int value) const + { + return Fahrenheit(value * convertFromInternal()); + } + + Fahrenheit operator/(int value) const + { + return Fahrenheit(value / convertFromInternal()); + } + + SIREUNITS_EXPORT Dimension::GeneralUnit operator+(const Dimension::GeneralUnit &other) const; + SIREUNITS_EXPORT Dimension::GeneralUnit operator-(const Dimension::GeneralUnit &other) const; + SIREUNITS_EXPORT Dimension::GeneralUnit operator*(const Dimension::GeneralUnit &other) const; + SIREUNITS_EXPORT Dimension::GeneralUnit operator/(const Dimension::GeneralUnit &other) const; + + protected: + QString unitString() const + { + return "F"; + } + }; - Fahrenheit& operator-=(const Dimension::Temperature &other) - { - return this->operator-=(Fahrenheit(other)); - } - - Fahrenheit operator*(double value) const - { - return Fahrenheit(value * convertFromInternal()); - } +#ifndef SIRE_SKIP_INLINE_FUNCTIONS - Fahrenheit operator/(double value) const + SIRE_ALWAYS_INLINE Fahrenheit operator*(double value, const Fahrenheit &temp) { - return Fahrenheit(value / convertFromInternal()); + return temp * value; } - Fahrenheit operator*(int value) const + SIRE_ALWAYS_INLINE Dimension::PhysUnit<0, 0, 0, 0, -1, 0, 0> operator/(double value, const Fahrenheit &temp) { - return Fahrenheit(value * convertFromInternal()); + return Dimension::PhysUnit<0, 0, 0, 0, -1, 0, 0>(value / temp.convertFromInternal()); } - Fahrenheit operator/(int value) const + SIRE_ALWAYS_INLINE Dimension::PhysUnit<0, 0, 0, 0, -1, 0, 0> operator/(int value, const Fahrenheit &temp) { - return Fahrenheit(value / convertFromInternal()); + return Dimension::PhysUnit<0, 0, 0, 0, -1, 0, 0>(value / temp.convertFromInternal()); } -protected: - QString unitString() const + SIRE_ALWAYS_INLINE Fahrenheit operator*(int value, const Fahrenheit &temp) { - return "F"; + return temp * value; } -}; - -#ifndef SIRE_SKIP_INLINE_FUNCTIONS - -SIRE_ALWAYS_INLINE Fahrenheit operator*(double value, const Fahrenheit &temp) -{ - return temp * value; -} - -SIRE_ALWAYS_INLINE Dimension::PhysUnit<0,0,0,0,-1,0,0> operator/(double value, const Fahrenheit &temp) -{ - return Dimension::PhysUnit<0,0,0,0,-1,0,0>(value / temp.convertFromInternal()); -} - -SIRE_ALWAYS_INLINE Dimension::PhysUnit<0,0,0,0,-1,0,0> operator/(int value, const Fahrenheit &temp) -{ - return Dimension::PhysUnit<0,0,0,0,-1,0,0>(value / temp.convertFromInternal()); -} - -SIRE_ALWAYS_INLINE Fahrenheit operator*(int value, const Fahrenheit &temp) -{ - return temp * value; -} -#endif //SIRE_SKIP_INLINE_FUNCTIONS +#endif // SIRE_SKIP_INLINE_FUNCTIONS -const Celsius celsius(1); -const Fahrenheit fahrenheit(1); + const Celsius celsius(1); + const Fahrenheit fahrenheit(1); } -SIRE_EXPOSE_CLASS( SireUnits::Dimension::TempBase ) -SIRE_EXPOSE_CLASS( SireUnits::Celsius ) -SIRE_EXPOSE_CLASS( SireUnits::Fahrenheit ) +SIRE_EXPOSE_CLASS(SireUnits::Dimension::TempBase) +SIRE_EXPOSE_CLASS(SireUnits::Celsius) +SIRE_EXPOSE_CLASS(SireUnits::Fahrenheit) SIRE_END_HEADER diff --git a/corelib/src/libs/SireUnits/units.h b/corelib/src/libs/SireUnits/units.h index 5407ebce2..4acb216c4 100644 --- a/corelib/src/libs/SireUnits/units.h +++ b/corelib/src/libs/SireUnits/units.h @@ -28,345 +28,346 @@ #ifndef SIREUNITS_UNITS_H #define SIREUNITS_UNITS_H -//skip this completely when parsing with gccxml as it is broken! +// skip this completely when parsing with gccxml as it is broken! #ifndef SKIP_BROKEN_GCCXML_PARTS #include #include #include "dimensions.h" +#include "generalunit.h" SIRE_BEGIN_HEADER namespace SireUnits { -/** This file defines physical constants, in internal units of this program + /** This file defines physical constants, in internal units of this program - We use the AKMA units (same as charmm) - Angstroms, Kilocalories per Mole, Atomic mass units + We use the AKMA units (same as charmm) + Angstroms, Kilocalories per Mole, Atomic mass units - energy = kcal mol-1 (thermal) (really MolarEnergy) - length = angstrom - mass = g mol-1 (really MolarMass) - time = AKMA time == 48.88821 fs == 0.04888821 ps - charge = unit electrons + energy = kcal mol-1 (thermal) (really MolarEnergy) + length = angstrom + mass = g mol-1 (really MolarMass) + time = AKMA time == 48.88821 fs == 0.04888821 ps + charge = unit electrons - Where necessary, physical constants were downloaded from - the NIST website (web pages referenced where appropriate). + Where necessary, physical constants were downloaded from + the NIST website (web pages referenced where appropriate). - Physical constants were last checked on 28/10/2008 -*/ + Physical constants were last checked on 28/10/2008 + */ -/** Avogadro's number */ -//http://physics.nist.gov/cgi-bin/cuu/Value?na|search_for=physchem_in! -const Dimension::Quantity mole( 6.02214179e23 ); + /** Avogadro's number */ + // http://physics.nist.gov/cgi-bin/cuu/Value?na|search_for=physchem_in! + const Dimension::Quantity mole(6.02214179e23); -const Dimension::Quantity dozen( 12 ); + const Dimension::Quantity dozen(12); -///////////////////////////////////////////////// -// Units of angle. Internal unit = radians // -///////////////////////////////////////////////// + ///////////////////////////////////////////////// + // Units of angle. Internal unit = radians // + ///////////////////////////////////////////////// -const Dimension::Angle radians( 1 ); -const Dimension::Angle radian( 1 ); + const Dimension::Angle radians(1); + const Dimension::Angle radian(1); -const Dimension::Angle degrees = radians * pi / 180.0; -const Dimension::Angle degree = degrees; + const Dimension::Angle degrees = radians * pi / 180.0; + const Dimension::Angle degree = degrees; -const Dimension::Angle angle_minute = degree / 60; -const Dimension::Angle angle_minutes = angle_minute; + const Dimension::Angle angle_minute = degree / 60; + const Dimension::Angle angle_minutes = angle_minute; -const Dimension::Angle angle_second = angle_minute / 60; -const Dimension::Angle angle_seconds = angle_second; + const Dimension::Angle angle_second = angle_minute / 60; + const Dimension::Angle angle_seconds = angle_second; -const Dimension::Angle octant = 45 * degrees; -const Dimension::Angle octants = octant; + const Dimension::Angle octant = 45 * degrees; + const Dimension::Angle octants = octant; -const Dimension::Angle sextant = 60 * degrees; -const Dimension::Angle sextants = sextant; + const Dimension::Angle sextant = 60 * degrees; + const Dimension::Angle sextants = sextant; -const Dimension::Angle quadrant = 90 * degrees; -const Dimension::Angle quadrants = quadrant; + const Dimension::Angle quadrant = 90 * degrees; + const Dimension::Angle quadrants = quadrant; -const Dimension::Angle gradian = quadrant / 100; -const Dimension::Angle gradians = gradian; -const Dimension::Angle grad = gradian; -const Dimension::Angle gon = gradian; + const Dimension::Angle gradian = quadrant / 100; + const Dimension::Angle gradians = gradian; + const Dimension::Angle grad = gradian; + const Dimension::Angle gon = gradian; -const Dimension::Angle revolution = 360 * degrees; -const Dimension::Angle revolutions = revolution; -const Dimension::Angle revs = revolution; + const Dimension::Angle revolution = 360 * degrees; + const Dimension::Angle revolutions = revolution; + const Dimension::Angle revs = revolution; -const Dimension::Angle circumference = revolution; + const Dimension::Angle circumference = revolution; -///////////////////////////////////////////////// -// Units of length. Internal unit = Angstroms // -///////////////////////////////////////////////// + ///////////////////////////////////////////////// + // Units of length. Internal unit = Angstroms // + ///////////////////////////////////////////////// -const Dimension::Length angstrom(1); -const Dimension::Length angstroms = angstrom; + const Dimension::Length angstrom(1); + const Dimension::Length angstroms = angstrom; -const Dimension::Length picometer( 0.01 * angstrom ); -const Dimension::Length nanometer( 1000 * picometer ); -const Dimension::Length micrometer( 1000 * nanometer ); -const Dimension::Length millimeter( 1000 * micrometer ); -const Dimension::Length centimeter( 10 * millimeter ); -const Dimension::Length meter( 100 * centimeter ); -const Dimension::Length kilometer( 1000 * meter ); + const Dimension::Length picometer(0.01 * angstrom); + const Dimension::Length nanometer(1000 * picometer); + const Dimension::Length micrometer(1000 * nanometer); + const Dimension::Length millimeter(1000 * micrometer); + const Dimension::Length centimeter(10 * millimeter); + const Dimension::Length meter(100 * centimeter); + const Dimension::Length kilometer(1000 * meter); -const Dimension::Length picometers = picometer; -const Dimension::Length nanometers = nanometer; -const Dimension::Length micrometers = micrometer; -const Dimension::Length millimeters = millimeter; -const Dimension::Length centimeters = centimeter; -const Dimension::Length meters = meter; -const Dimension::Length kilometers = kilometer; + const Dimension::Length picometers = picometer; + const Dimension::Length nanometers = nanometer; + const Dimension::Length micrometers = micrometer; + const Dimension::Length millimeters = millimeter; + const Dimension::Length centimeters = centimeter; + const Dimension::Length meters = meter; + const Dimension::Length kilometers = kilometer; -//http://physics.nist.gov/cgi-bin/cuu/Value?bohrrada0|search_for=bohr -const Dimension::Length bohr_radii( 0.52917720859 * angstrom ); + // http://physics.nist.gov/cgi-bin/cuu/Value?bohrrada0|search_for=bohr + const Dimension::Length bohr_radii(0.52917720859 * angstrom); -const Dimension::Length inch( 2.54 * centimeter ); -const Dimension::Length foot( 12 * inch ); -const Dimension::Length yard( 3 * foot ); -const Dimension::Length mile( 1760 * yard ); + const Dimension::Length inch(2.54 * centimeter); + const Dimension::Length foot(12 * inch); + const Dimension::Length yard(3 * foot); + const Dimension::Length mile(1760 * yard); -const Dimension::Length inches = inch; -const Dimension::Length feet = foot; -const Dimension::Length yards = yard; -const Dimension::Length miles = mile; + const Dimension::Length inches = inch; + const Dimension::Length feet = foot; + const Dimension::Length yards = yard; + const Dimension::Length miles = mile; -///////////////////////////////////////////////// -// Units of area. Internal unit = Angstroms^2 // -///////////////////////////////////////////////// + ///////////////////////////////////////////////// + // Units of area. Internal unit = Angstroms^2 // + ///////////////////////////////////////////////// -const Dimension::Area angstrom2 = angstrom * angstrom; -const Dimension::Area picometer2 = picometer * picometer; -const Dimension::Area nanometer2 = nanometer * nanometer; + const Dimension::Area angstrom2 = angstrom * angstrom; + const Dimension::Area picometer2 = picometer * picometer; + const Dimension::Area nanometer2 = nanometer * nanometer; -const Dimension::Area meter2 = meter * meter; + const Dimension::Area meter2 = meter * meter; -///////////////////////////////////////////////// -// Units of volume. Internal unit = Angstroms^3 // -///////////////////////////////////////////////// + ///////////////////////////////////////////////// + // Units of volume. Internal unit = Angstroms^3 // + ///////////////////////////////////////////////// -const Dimension::Volume angstrom3 = angstrom * angstrom * angstrom; -const Dimension::Volume picometer3 = picometer * picometer * picometer; -const Dimension::Volume nanometer3 = nanometer * nanometer * nanometer; + const Dimension::Volume angstrom3 = angstrom * angstrom * angstrom; + const Dimension::Volume picometer3 = picometer * picometer * picometer; + const Dimension::Volume nanometer3 = nanometer * nanometer * nanometer; -const Dimension::Volume meter3 = meter * meter * meter; + const Dimension::Volume meter3 = meter * meter * meter; -/////////////////////////////////////////////////////// -// Units of mass. Internal unit = g mol-1 // -/////////////////////////////////////////////////////// + /////////////////////////////////////////////////////// + // Units of mass. Internal unit = g mol-1 // + /////////////////////////////////////////////////////// -const Dimension::MolarMass g_per_mol(1); + const Dimension::MolarMass g_per_mol(1); -const Dimension::Mass gram( mole * g_per_mol ); -const Dimension::Mass kilogram( 1000 * gram ); -const Dimension::Mass tonne( 1000 * kilogram ); + const Dimension::Mass gram(mole *g_per_mol); + const Dimension::Mass kilogram(1000 * gram); + const Dimension::Mass tonne(1000 * kilogram); -const Dimension::Mass milligram( 0.001 * gram ); -const Dimension::Mass microgram( 0.001 * milligram ); -const Dimension::Mass nanogram( 0.001 * microgram ); -const Dimension::Mass picogram( 0.001 * nanogram ); -const Dimension::Mass femtogram( 0.001 * picogram ); + const Dimension::Mass milligram(0.001 * gram); + const Dimension::Mass microgram(0.001 * milligram); + const Dimension::Mass nanogram(0.001 * microgram); + const Dimension::Mass picogram(0.001 * nanogram); + const Dimension::Mass femtogram(0.001 * picogram); -const Dimension::MolarMass kg_per_mol( 1000 * g_per_mol ); -const Dimension::MolarMass tonne_per_mol( 1000 * kg_per_mol ); -const Dimension::MolarMass mg_per_mol( 0.001 * g_per_mol ); -const Dimension::MolarMass ug_per_mol( 0.001 * mg_per_mol ); -const Dimension::MolarMass ng_per_mol( 0.001 * ug_per_mol ); -const Dimension::MolarMass pg_per_mol( 0.001 * ng_per_mol ); -const Dimension::MolarMass fg_per_mol( 0.001 * pg_per_mol ); + const Dimension::MolarMass kg_per_mol(1000 * g_per_mol); + const Dimension::MolarMass tonne_per_mol(1000 * kg_per_mol); + const Dimension::MolarMass mg_per_mol(0.001 * g_per_mol); + const Dimension::MolarMass ug_per_mol(0.001 * mg_per_mol); + const Dimension::MolarMass ng_per_mol(0.001 * ug_per_mol); + const Dimension::MolarMass pg_per_mol(0.001 * ng_per_mol); + const Dimension::MolarMass fg_per_mol(0.001 * pg_per_mol); -/////////////////////////////////////////////////////// -// Units of Charge. Internal unit = |e| // -/////////////////////////////////////////////////////// + /////////////////////////////////////////////////////// + // Units of Charge. Internal unit = |e| // + /////////////////////////////////////////////////////// -const Dimension::Charge mod_electron(1); -const Dimension::MolarCharge faraday(1); + const Dimension::Charge mod_electron(1); + const Dimension::MolarCharge faraday(1); -//http://physics.nist.gov/cgi-bin/cuu/Value?e|search_for=elecmag_in! -const Dimension::Charge coulomb = mod_electron / 1.602176487e-19; -const Dimension::MolarCharge coulomb_per_mol = coulomb / mole; + // http://physics.nist.gov/cgi-bin/cuu/Value?e|search_for=elecmag_in! + const Dimension::Charge coulomb = mod_electron / 1.602176487e-19; + const Dimension::MolarCharge coulomb_per_mol = coulomb / mole; -const Dimension::Charge e_charge = -mod_electron; + const Dimension::Charge e_charge = -mod_electron; -///////////////////////////////////////////////// -// Units of Energy. Internal unit = kcal mol-1 // -///////////////////////////////////////////////// + ///////////////////////////////////////////////// + // Units of Energy. Internal unit = kcal mol-1 // + ///////////////////////////////////////////////// -const Dimension::MolarEnergy kcal_per_mol(1); -const Dimension::Energy kcal = mole * kcal_per_mol; + const Dimension::MolarEnergy kcal_per_mol(1); + const Dimension::Energy kcal = mole * kcal_per_mol; -const Dimension::MolarEnergy cal_per_mol = 0.001 * kcal_per_mol; -const Dimension::Energy cal = 0.001 * kcal; + const Dimension::MolarEnergy cal_per_mol = 0.001 * kcal_per_mol; + const Dimension::Energy cal = 0.001 * kcal; -const Dimension::MolarEnergy kJ_per_mol = kcal_per_mol / 4.184; -const Dimension::Energy kilojoule = mole * kJ_per_mol; + const Dimension::MolarEnergy kJ_per_mol = kcal_per_mol / 4.184; + const Dimension::Energy kilojoule = mole * kJ_per_mol; -const Dimension::MolarEnergy MJ_per_mol = 1000 * kJ_per_mol; -const Dimension::Energy megajoule = 1000 * kilojoule; + const Dimension::MolarEnergy MJ_per_mol = 1000 * kJ_per_mol; + const Dimension::Energy megajoule = 1000 * kilojoule; -const Dimension::MolarEnergy J_per_mol = 0.001 * kJ_per_mol; -const Dimension::Energy joule = 0.001 * kilojoule; + const Dimension::MolarEnergy J_per_mol = 0.001 * kJ_per_mol; + const Dimension::Energy joule = 0.001 * kilojoule; -/** Conversion factor from international kcal mol-1 to internal units */ -const Dimension::MolarEnergy int_kcal_per_mol( 4.1868 * kJ_per_mol ); -const Dimension::MolarEnergy int_cal_per_mol( 0.001 * int_kcal_per_mol ); + /** Conversion factor from international kcal mol-1 to internal units */ + const Dimension::MolarEnergy int_kcal_per_mol(4.1868 * kJ_per_mol); + const Dimension::MolarEnergy int_cal_per_mol(0.001 * int_kcal_per_mol); -const Dimension::Energy int_kcal( mole * int_kcal_per_mol ); -const Dimension::Energy int_cal( 0.001 * int_kcal ); + const Dimension::Energy int_kcal(mole *int_kcal_per_mol); + const Dimension::Energy int_cal(0.001 * int_kcal); -//http://physics.nist.gov/cgi-bin/cuu/Value?hr|search_for=hartree -const Dimension::Energy hartree(4.35974394e-18 * joule); + // http://physics.nist.gov/cgi-bin/cuu/Value?hr|search_for=hartree + const Dimension::Energy hartree(4.35974394e-18 * joule); -//////////////////////////////////////////////////////////// -// Units of time. Internal unit = akma_time == 48.8882 fs // -//////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////// + // Units of time. Internal unit = akma_time == 48.8882 fs // + //////////////////////////////////////////////////////////// -const Dimension::Time akma_time(1); + const Dimension::Time akma_time(1); -const Dimension::Time second( std::sqrt( (kg_per_mol * meter * meter) / J_per_mol ) ); -const Dimension::Time millisecond = 0.001 * second; -const Dimension::Time microsecond = 0.001 * millisecond; -const Dimension::Time nanosecond = 0.001 * microsecond; -const Dimension::Time picosecond = 0.001 * nanosecond; -const Dimension::Time femtosecond = 0.001 * picosecond; + const Dimension::Time second(std::sqrt((kg_per_mol * meter * meter) / J_per_mol)); + const Dimension::Time millisecond = 0.001 * second; + const Dimension::Time microsecond = 0.001 * millisecond; + const Dimension::Time nanosecond = 0.001 * microsecond; + const Dimension::Time picosecond = 0.001 * nanosecond; + const Dimension::Time femtosecond = 0.001 * picosecond; -const Dimension::Time minute( 60 * second ); -const Dimension::Time hour( 60 * minute ); -const Dimension::Time day( 24 * hour ); -const Dimension::Time week( 7 * day ); -const Dimension::Time fortnight( 2 * week ); + const Dimension::Time minute(60 * second); + const Dimension::Time hour(60 * minute); + const Dimension::Time day(24 * hour); + const Dimension::Time week(7 * day); + const Dimension::Time fortnight(2 * week); -///////////////////////////////////////////////////////////// -// Units of velocity. Internal unit = Angstrom / AKMA time // -///////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////// + // Units of velocity. Internal unit = Angstrom / AKMA time // + ///////////////////////////////////////////////////////////// -const Dimension::Velocity akma_velocity(1); + const Dimension::Velocity akma_velocity(1); -const Dimension::Velocity angstroms_per_fs( angstrom / femtosecond ); -const Dimension::Velocity meters_per_second( meter / second ); -const Dimension::Velocity kilometers_per_hour( kilometer / hour ); -const Dimension::Velocity miles_per_hour( mile / hour ); -const Dimension::Velocity mph = miles_per_hour; -const Dimension::Velocity kph = kilometers_per_hour; + const Dimension::Velocity angstroms_per_fs(angstrom / femtosecond); + const Dimension::Velocity meters_per_second(meter / second); + const Dimension::Velocity kilometers_per_hour(kilometer / hour); + const Dimension::Velocity miles_per_hour(mile / hour); + const Dimension::Velocity mph = miles_per_hour; + const Dimension::Velocity kph = kilometers_per_hour; -////////////////////////////////////////////////////////// -// Units of force. Internal units = kcal mol-1 A-1 // -////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////// + // Units of force. Internal units = kcal mol-1 A-1 // + ////////////////////////////////////////////////////////// -/** Convert a force in Newtons to internal units */ -const Dimension::Force newton( joule / meter ); + /** Convert a force in Newtons to internal units */ + const Dimension::Force newton(joule / meter); -/** Weights */ -const Dimension::Force ounce = 0.27801385095 * newton; -const Dimension::Force pound = 16 * ounce; -const Dimension::Force stone = 14 * pound; -const Dimension::Force hundredweight = 8 * stone; + /** Weights */ + const Dimension::Force ounce = 0.27801385095 * newton; + const Dimension::Force pound = 16 * ounce; + const Dimension::Force stone = 14 * pound; + const Dimension::Force hundredweight = 8 * stone; -////////////////////////////////////////////////////////// -// Units of pressure. Internal units = kcal mol-1 A-2 // -////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////// + // Units of pressure. Internal units = kcal mol-1 A-2 // + ////////////////////////////////////////////////////////// -const Dimension::Pressure pascal = newton / (meter*meter); + const Dimension::Pressure pascal = newton / (meter * meter); -const Dimension::Pressure bar = 100000 * pascal; -const Dimension::Pressure atm = 101325 * pascal; + const Dimension::Pressure bar = 100000 * pascal; + const Dimension::Pressure atm = 101325 * pascal; -const Dimension::Pressure psi = pound / (inch*inch); -const Dimension::Pressure mmHg = 133.322 * pascal; + const Dimension::Pressure psi = pound / (inch * inch); + const Dimension::Pressure mmHg = 133.322 * pascal; -////////////////////////////////////////////////////////// -// Units of temperature. Internal units = Kelvin // -////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////// + // Units of temperature. Internal units = Kelvin // + ////////////////////////////////////////////////////////// -const Dimension::Temperature kelvin(1); + const Dimension::Temperature kelvin(1); -// other temperature units defined in temperature.h + // other temperature units defined in temperature.h -////////////////////////////////////////////////////////// -// Now some miscellaneous units // -////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////// + // Now some miscellaneous units // + ////////////////////////////////////////////////////////// -/** Convert the units of current (amps) */ -const Dimension::Current amp = coulomb / second; + /** Convert the units of current (amps) */ + const Dimension::Current amp = coulomb / second; -/** Volts */ -const Dimension::Potential volt = joule / coulomb; + /** Volts */ + const Dimension::Potential volt = joule / coulomb; -/** Convert the units of capacitance (farads) */ -const Dimension::Capacitance farad = coulomb / volt; + /** Convert the units of capacitance (farads) */ + const Dimension::Capacitance farad = coulomb / volt; -/** Convert power in Watts */ -const Dimension::Power watt = joule / second; -const Dimension::MolarPower watt_per_mol = J_per_mol / second; + /** Convert power in Watts */ + const Dimension::Power watt = joule / second; + const Dimension::MolarPower watt_per_mol = J_per_mol / second; -/////////////////////////////////////////////////////////// -// Now physical constants converted into internal units. // -// The values of these are taken from the 1998 CODATA // -// values - see fundemental_constants.pdf in techdocs // -/////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////// + // Now physical constants converted into internal units. // + // The values of these are taken from the 1998 CODATA // + // values - see fundemental_constants.pdf in techdocs // + /////////////////////////////////////////////////////////// -/** Speed of light in a vacuum */ -//http://physics.nist.gov/cgi-bin/cuu/Value?c|search_for=c -const Dimension::Velocity c = 299792458 * (meter / second); + /** Speed of light in a vacuum */ + // http://physics.nist.gov/cgi-bin/cuu/Value?c|search_for=c + const Dimension::Velocity c = 299792458 * (meter / second); -/** Epsilon_0 (electrostatic constant) 8.854187817e-12 F m-1 */ -//http://physics.nist.gov/cgi-bin/cuu/Value?ep0|search_for=permittivity -const double epsilon0 = 8.854187817e-12 * (farad / meter); + /** Epsilon_0 (electrostatic constant) 8.854187817e-12 F m-1 */ + // http://physics.nist.gov/cgi-bin/cuu/Value?ep0|search_for=permittivity + const Dimension::GeneralUnit epsilon0(8.854187817e-12 * (farad / meter)); -/** 4 * pi * epsilon_0 */ -const double four_pi_eps0 = 4.0 * SireMaths::pi * epsilon0; + /** 4 * pi * epsilon_0 */ + const Dimension::GeneralUnit four_pi_eps0(4.0 * SireMaths::pi * epsilon0); -/** 1 / (4 * pi * epsilon0) */ -const double one_over_four_pi_eps0 = 1.0 / four_pi_eps0; + /** 1 / (4 * pi * epsilon0) */ + const Dimension::GeneralUnit one_over_four_pi_eps0(1.0 / four_pi_eps0); -/** Gas constant (8.314472 J mol-1 K-1) */ -//http://physics.nist.gov/cgi-bin/cuu/Value?r|search_for=gas -const double gasr = 8.314472 * (J_per_mol / kelvin); + /** Gas constant (8.314472 J mol-1 K-1) */ + // http://physics.nist.gov/cgi-bin/cuu/Value?r|search_for=gas + const Dimension::GeneralUnit gasr(8.314472 * (J_per_mol / kelvin)); -/** Boltzmann constant J K-1 (is equal to gasr in internal units of kcal mol-1 K-1) */ -const double k_boltz = gasr; + /** Boltzmann constant J K-1 (is equal to gasr in internal units of kcal mol-1 K-1) */ + const Dimension::GeneralUnit k_boltz = gasr; -/** Magnetic constant, mu0, 4pi * 10-7 N A-2 */ -const double mu0 = 4.0e-7 * pi * (newton / (amp*amp)); + /** Magnetic constant, mu0, 4pi * 10-7 N A-2 */ + const Dimension::GeneralUnit mu0(4.0e-7 * pi * (newton / (amp * amp))); -/** Newton's gravitational constant */ -//http://physics.nist.gov/cgi-bin/cuu/Value?bg|search_for=gravitational -const double G_newton = 6.67428e-11 * ((meter*meter*meter) / (kilogram * second * second)); + /** Newton's gravitational constant */ + // http://physics.nist.gov/cgi-bin/cuu/Value?bg|search_for=gravitational + const Dimension::GeneralUnit G_newton(6.67428e-11 * ((meter * meter * meter) / (kilogram * second * second))); -/** Acceleration due to gravity on Earth */ -const Dimension::Acceleration g_accel = 9.8 * meter / (second*second); + /** Acceleration due to gravity on Earth */ + const Dimension::Acceleration g_accel = 9.8 * meter / (second * second); -/** Planck's constant */ -//http://physics.nist.gov/cgi-bin/cuu/Value?h|search_for=planck -const double h_planck = 6.62606896e-34 * (joule * second); + /** Planck's constant */ + // http://physics.nist.gov/cgi-bin/cuu/Value?h|search_for=planck + const Dimension::GeneralUnit h_planck(6.62606896e-34 * (joule * second)); -/** Plank / 2pi */ -const double h_slash = h_planck / (2.0*pi); + /** Plank / 2pi */ + const Dimension::GeneralUnit h_slash(h_planck / (2.0 * pi)); -/** Mass of an electron */ -//http://physics.nist.gov/cgi-bin/cuu/Value?me|search_for=mass -const Dimension::Mass electron_mass = 9.10938215e-31 * kilogram; + /** Mass of an electron */ + // http://physics.nist.gov/cgi-bin/cuu/Value?me|search_for=mass + const Dimension::Mass electron_mass = 9.10938215e-31 * kilogram; -/** Mass of a proton */ -//http://physics.nist.gov/cgi-bin/cuu/Value?mp|search_for=mass -const Dimension::Mass proton_mass = 1.672621637e-27 * kilogram; + /** Mass of a proton */ + // http://physics.nist.gov/cgi-bin/cuu/Value?mp|search_for=mass + const Dimension::Mass proton_mass = 1.672621637e-27 * kilogram; -/** Mass of a neutron */ -//http://physics.nist.gov/cgi-bin/cuu/Value?mn|search_for=mass -const Dimension::Mass neutron_mass = 1.674927211e-27 * kilogram; + /** Mass of a neutron */ + // http://physics.nist.gov/cgi-bin/cuu/Value?mn|search_for=mass + const Dimension::Mass neutron_mass = 1.674927211e-27 * kilogram; -/** Atomic mass constant */ -//http://physics.nist.gov/cgi-bin/cuu/Value?u|search_for=mass -const Dimension::Mass atomic_mass_constant = 1.660538782e-27 * kilogram; + /** Atomic mass constant */ + // http://physics.nist.gov/cgi-bin/cuu/Value?u|search_for=mass + const Dimension::Mass atomic_mass_constant = 1.660538782e-27 * kilogram; -/** Molar volume of an ideal gas (273.15 K, 101.325 kPa) */ -//http://physics.nist.gov/cgi-bin/cuu/Value?mvolstd|search_for=molar+volume -const Dimension::MolarVolume molar_volume = 22.413996e-3 * (meter*meter*meter) / mole; + /** Molar volume of an ideal gas (273.15 K, 101.325 kPa) */ + // http://physics.nist.gov/cgi-bin/cuu/Value?mvolstd|search_for=molar+volume + const Dimension::MolarVolume molar_volume = 22.413996e-3 * (meter * meter * meter) / mole; } diff --git a/doc/source/cheatsheet/search.rst b/doc/source/cheatsheet/search.rst index c8ac94986..ca2d4f07c 100644 --- a/doc/source/cheatsheet/search.rst +++ b/doc/source/cheatsheet/search.rst @@ -213,7 +213,7 @@ as the result. This can be summarised as a table. +----------+---------------------+---------------------+------------------------+----------------------+------------------------+----------------------+ | Chain | chains with atom | chains with bond | chains with residue | N/A | chains in segment | chains in molecule | +----------+---------------------+---------------------+------------------------+----------------------+------------------------+----------------------+ -| Segment | segments with atomv | segments with bond | segments with residue | segments with chain | N/A | segments in molecule | +| Segment | segments with atoms | segments with bond | segments with residue | segments with chain | N/A | segments in molecule | +----------+---------------------+---------------------+------------------------+----------------------+------------------------+----------------------+ | Molecule | molecules with atom | molecules with bond | molecules with residue | molecules with chain | molecules with segment | N/A | +----------+---------------------+---------------------+------------------------+----------------------+------------------------+----------------------+ @@ -402,7 +402,7 @@ For example; * ``atoms in residues with count(atomname CA) == 1`` - match all atoms in residues that contain a single atom called ``CA`` * ``(molecules with count(element O) == 1) and (molecules with count(element H) == 2) and (molecules with count(atoms) == 3)`` - - match all molecules that contain there atoms, and that have one oxygen atom + match all molecules that contain three atoms, and that have one oxygen atom and have two hydrogen atoms (i.e. are water molecules). Searching by Charge or Mass @@ -453,7 +453,7 @@ imprecision issues experienced when searching for views by charge. The approximate comparison operators are; * ``=~`` - approximate equal to. :func:`sire.search.approx_equal` -* ``!~`` - not approximates equal to. :func:`sire.search_approx_not_equal` +* ``!~`` - not approximates equal to. :func:`sire.search.approx_not_equal` * ``>~`` - greater than (but not approximately equal to). :func:`sire.search.approx_greater` * ``<~`` - less than (but not approximately equal to). :func:`sire.search.approx_less` * ``>=~`` - greater than or approximately equal to. :func:`sire.search.approx_greater_equal` diff --git a/doc/source/conf.py b/doc/source/conf.py index 0d1781ce7..57e70eb71 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -7,8 +7,6 @@ from __future__ import print_function import sire -import sys -import glob import os # -- General configuration ----------------------------------------------- @@ -17,33 +15,33 @@ # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.viewcode', - 'sphinx.ext.autosummary', - 'sphinx.ext.napoleon', - 'sphinx.ext.mathjax', - 'sphinxcontrib.programoutput', - 'sphinx_issues', + "sphinx.ext.autodoc", + "sphinx.ext.viewcode", + "sphinx.ext.autosummary", + "sphinx.ext.napoleon", + "sphinx.ext.mathjax", + "sphinxcontrib.programoutput", + "sphinx_issues", ] # Github repo -issues_github_path = 'openbiosim/sire' +issues_github_path = "openbiosim/sire" # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. # source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'sire' -copyright = u'2006-2022' +project = "sire" +copyright = "2006-2022" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -76,7 +74,7 @@ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -language = 'en' +language = "en" # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: @@ -86,9 +84,9 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ['_build', '*_test*'] +exclude_patterns = ["_build", "*_test*"] -# The reST default role (used for this markup: `text`) to use for all documents. +# The reST default role (used for this markup: `text`) to use for all documents default_role = "autolink" # If true, '()' will be appended to :func: etc. cross-reference text. @@ -96,29 +94,31 @@ # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # -- options for mathjax # note there is no protocol given here to avoid mixing http with https # see: http://docs.mathjax.org/en/latest/start.html#secure-cdn-access -mathjax_path = ("https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?" - "config=TeX-AMS-MML_HTMLorMML") +mathjax_path = ( + "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?" + "config=TeX-AMS-MML_HTMLorMML" +) # -- Options for HTML output --------------------------------------------- # theme -html_theme = 'furo' +html_theme = "furo" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -128,23 +128,26 @@ "light_css_variables": { "font-stack": "Changa, sans-serif", "font-stack--monospace": "Roboto Mono, monospace", - "color-foreground-primary": "#dddddd", # main text and headings - "color-foreground-secondary": "#cccccc", # secondary text - "color-foreground-muted" : "#d0d0d0", # muted text - "color-foreground-border": "#923eb1", # for content borders - "color-background-primary": "#160f30", # for content - "color-background-secondary": "#201146", # for navigation + ToC - "color-background-hover": "#4f4fb0", # for navigation-item hover + "color-foreground-primary": "#dddddd", # main text and headings + "color-foreground-secondary": "#cccccc", # secondary text + "color-foreground-muted": "#d0d0d0", # muted text + "color-foreground-border": "#923eb1", # for content borders + "color-background-primary": "#160f30", # for content + "color-background-secondary": "#201146", # for navigation + ToC + "color-background-hover": "#4f4fb0", # for navigation-item hover "color-background-hover--transparent": "#4f4fb000", - "color-background-border": "#403333", # for UI borders - "color-background-item": "#411a30", # for "background" items (eg: copybutton) - "color-announcement-background": "#000000dd", # announcements - "color-announcement-text": "#eeebee", # announcements - "color-admonition-title-background--note": "#FFFFFF33", # Note background - "color-admonition-title-background--warning": "#FF000033", # Warning background - "color-admonition-background": "#FFFFFF11", # Admonition backgrounds - "color-brand-primary": "#eeeeee", # brand colors (sidebar titles) - "color-brand-content": "#00dfef", # brand colors (hyperlink color) + "color-background-border": "#403333", # for UI borders + "color-background-item": "#411a30", # for "background" items + # (eg: copybutton) + "color-announcement-background": "#000000dd", # announcements + "color-announcement-text": "#eeebee", # announcements + "color-admonition-title-background--note": "#FFFFFF33", + # Note background + "color-admonition-title-background--warning": "#FF000033", + # Warning background + "color-admonition-background": "#FFFFFF11", # Admonition backgrounds + "color-brand-primary": "#eeeeee", # brand colors (sidebar titles) + "color-brand-content": "#00dfef", # brand colors (hyperlink color) "color-highlight-on-target": "#333300", # Highlighted text background }, } @@ -171,46 +174,44 @@ # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -html_favicon = None +html_favicon = "images/favicon.png" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] html_css_files = [ - 'css/custom_fonts.css', - 'css/custom_style.css', - 'css/custom_pygments.css' + "css/custom_fonts.css", + "css/custom_style.css", + "css/custom_pygments.css", ] -html_js_files = [ - 'js/custom.js' -] +html_js_files = ["js/custom.js"] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -html_last_updated_fmt = '%b %d, %Y' +html_last_updated_fmt = "%b %d, %Y" # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {'**': ['sourcelink.html', 'globaltoc.html']} +# html_sidebars = {'**': ['sourcelink.html', 'globaltoc.html']} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. html_show_sourcelink = False @@ -224,13 +225,13 @@ # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'SireDoc' +htmlhelp_basename = "SireDoc" # -- Options for LaTeX output -------------------------------------------- @@ -238,53 +239,47 @@ latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - 'preamble': r"\usepackage{amsmath,amssymb}", + "preamble": r"\usepackage{amsmath,amssymb}", } # Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, author, documentclass [howto/manual]). +# (source start file, target name, title, author, documentclass [howto/manual]) latex_documents = [ - ('index', 'sire.tex', u'Sire Documentation', - u'Michel Lab', 'manual'), + ("index", "sire.tex", "Sire Documentation", "OpenBioSim", "manual"), ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output -------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [ - ('index', 'Sire', u'Sire Documentation', - [""], 1) -] +man_pages = [("index", "Sire", "Sire Documentation", [""], 1)] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------ @@ -293,20 +288,25 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'Sire', u'Sire Documentation', - "", 'Sire', - 'Sire molecular simulation framework.', - 'Miscellaneous'), + ( + "index", + "Sire", + "Sire Documentation", + "", + "Sire", + "Sire molecular simulation framework.", + "Miscellaneous", + ), ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # ----------------------------------------------------------------------------- # Autosummary @@ -314,14 +314,13 @@ autosummary_generate = True autodoc_default_options = { - 'members': None, # Include all members (methods). - 'special-members': False, - 'exclude-members': '__dict__,__weakref__', # Exclude "standard" methods. + "members": None, # Include all members (methods). + "special-members": False, + "exclude-members": "__dict__,__weakref__", # Exclude "standard" methods. "private-members": False, } # spell checking -spelling_lang = 'en_US' -spelling_word_list_filename = 'spelling_wordlist.txt' +spelling_lang = "en_US" +spelling_word_list_filename = "spelling_wordlist.txt" spelling_show_suggestions = True - diff --git a/doc/source/features.rst b/doc/source/features.rst index c976c7cf6..56c7f104b 100644 --- a/doc/source/features.rst +++ b/doc/source/features.rst @@ -5,7 +5,7 @@ Features :mod:`sire` is a powerful Python/C++ module for loading and manipulating molecular (predominantly biomolecular) systems. -* :doc:`Load an save ` +* :doc:`Load and save ` molecules from a number of :doc:`molecular file formats `. This includes Amber, CHARMM and GROMACS files. diff --git a/doc/source/images/favicon.png b/doc/source/images/favicon.png new file mode 100644 index 000000000..abedad0c6 Binary files /dev/null and b/doc/source/images/favicon.png differ diff --git a/doc/source/images/logo.svg b/doc/source/images/logo.svg index af2baf0f3..ccea389f5 100644 --- a/doc/source/images/logo.svg +++ b/doc/source/images/logo.svg @@ -1,67 +1,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + diff --git a/doc/source/install.rst b/doc/source/install.rst index 29c90c979..13d3ffac0 100644 --- a/doc/source/install.rst +++ b/doc/source/install.rst @@ -3,15 +3,15 @@ Installation ============ Binary packages for :mod:`sire` are available on MacOS, Linux and Windows -running on Intel (X86-64) or ARM64 processors. +running on Intel/AMD (X86-64) or ARM64 processors. :mod:`sire` can be compiled on any UNIX or Windows-compatible operating system running on X86-64, ARM64 or PowerPC processors. You have a range of options for installing the software. -No-installation - Run in a Web Browser -====================================== +1. No-installation - Run in a Web Browser +========================================= We run a completely free `JupyterHub `__ on which we have sire installed. @@ -45,8 +45,8 @@ to learn how to use :mod:`sire` or the use this service to explore and learn :mod:`sire`. Do not use it for production work. -Easy installation - Run in a conda environment -============================================== +2. Easy installation - Run in a conda environment +================================================= The easiest way to install :mod:`sire` is in a new `conda environment `__. @@ -57,8 +57,9 @@ as this is pre-configured to use `conda-forge `__, and bundles `mamba `__, which is a fast drop-in replacement for `conda `__. -Option 1. Installing a new copy of ``mambaforge`` -------------------------------------------------- +.. _Install_Mambaforge: +Either... Install a new copy of ``mambaforge`` +---------------------------------------------- To install a new copy of `mambaforge `__, @@ -73,8 +74,8 @@ Once installed, you should be able to run the ``mamba`` command to install other packages (e.g. ``mamba -h`` will print out help on how to use the ``mamba`` command). -Option 2. Using an existing anaconda/miniconda install ------------------------------------------------------- +Or... Use an existing anaconda/miniconda install +------------------------------------------------ If you want to use an existing anaconda or miniconda installation, then first open a terminal with that distribution activated. @@ -94,14 +95,15 @@ drop-in replacement for ``conda``, so first install ``mamba``. This should install mamba. If this fails, then your anaconda or miniconda environment is likely quite full, or else it is outdated. We recommend -going back to Option 1 and installing a new copy of ``mambaforge``. +going back and following `the instructions <_Install_Mambaforge>` +to install a new copy of ``mambaforge``. If this works, then you should now be able to run the ``mamba`` command to install other packages (e.g. ``mamba -h`` will print out help on how to use the ``mamba`` command). -Installing sire into a new environment --------------------------------------- +And then... Install sire into a new environment +----------------------------------------------- We recommend that :mod:`sire` is installed into a new (clean) environment. This minimises the risk of failures caused by incompatible dependencies. @@ -162,8 +164,8 @@ We encourage you to take a look at :doc:`the tutorial ` to learn how to use :mod:`sire` or the :doc:`quickstart guide ` if you want an overview. -Also easy installation - Run in a container -=========================================== +3. Also easy installation - Run in a container +============================================== Another route to install :mod:`sire` is to download and run our pre-built containers. These can be run via @@ -219,8 +221,8 @@ We encourage you to take a look at :doc:`the tutorial ` to learn how to use :mod:`sire` or the :doc:`quickstart guide ` if you want an overview. -Harder installation - Compile from source -========================================= +4. Harder installation - Compile from source +============================================ Sometimes you will want to compile and run :mod:`sire` from source. This could be because we don't distribute a binary package for your @@ -230,7 +232,7 @@ branch if you are a developer). You compile :mod:`sire` into an existing anaconda / miniconda environment. Please create and activate an environment, e.g. by following -the "Option 1" instructions to install a fresh ``mambaforge`` and +`the instructions <_Install_Mambaforge>` to install a fresh ``mambaforge`` and then creating and activating Python 3.9 environment called ``openbiosim``. diff --git a/docker/sire-generate-wrappers/README.md b/docker/sire-generate-wrappers/README.md index ffc280b62..5a2d7547e 100644 --- a/docker/sire-generate-wrappers/README.md +++ b/docker/sire-generate-wrappers/README.md @@ -1,9 +1,9 @@ # Generating the Python wrappers This is a container that is used to consistently generate -the Python wrappers for Sire. The container has a working +the Python wrappers for sire. The container has a working version of Py++ in a miniconda that also has all of the header -files that are needed for Sire. +files that are needed for sire. ## Running the container @@ -11,16 +11,24 @@ The simplest way to start is to run the container that we've made already. Do this by typing; ``` -docker run -it siremol/sire-generate-wrappers +$ docker run -it openbiosim/sire-generate-wrappers:x86 +``` + +on Intel/AMD (X86-64) systems, and + +``` +$ docker run -it openbiosim/sire-generate-wrappers:arm64 ``` +on Apple / ARM64 systems. + Assuming you have docker installed and working, this should pull the container from docker hub, and then start a bash prompt in that container. You should see something like this; ``` -Unable to find image 'siremol/sire-generate-wrappers:latest' locally +Unable to find image 'openbiosim/sire-generate-wrappers:arm64' locally Trying to pull repository docker.io/siremol/sire-generate-wrappers ... latest: Pulling from docker.io/siremol/sire-generate-wrappers a2abf6c4d29d: Pull complete @@ -41,7 +49,7 @@ Status: Downloaded newer image for siremol/sire-generate-wrappers:latest ## Generating the wrappers -You generate the wrappers for your chosen branch of Sire by typing; +You generate the wrappers for your chosen branch of sire by typing; ``` (base) root:~# generate_wrappers --branch {BRANCH_NAME} @@ -61,7 +69,7 @@ a long time! ## Checking the wrappers The `generate_wrappers` command will check out your branch -to the folder `$HOME/Sire`. Feel free to explore this +to the folder `$HOME/sire`. Feel free to explore this folder and run commands manually if there are any problems. You can check which wrappers were changed by running @@ -81,7 +89,7 @@ where `${YOUR NAME}` is your real name, as on GitHub, and these in double quotes. This will use `git config` to set those values, before -running `git add` in `$HOME/Sire`, and then running +running `git add` in `$HOME/sire`, and then running `git commit` and `git push`. The `git push` command will ask you for your GitHub @@ -90,21 +98,27 @@ be pushed if these are entered and are correct. Assuming everything has worked, then congratulations! You have successfully generated and pushed your new -Sire Python wrappers. +sire Python wrappers. -## Using the container against an external Sire directory +## Using the container against an external sire directory You may wish to use this container to create wrappers for -a Sire directory on your computer. To do this, you can mount -the Sire directory into the container via +a sire directory on your computer. To do this, you can mount +the sire directory into the container via + +``` +docker run -it -v /path/to/sire:/root/sire openbiosim/sire-generate-wrappers:x86 +``` + +or ``` -docker run -it -v /path/to/Sire:/root/Sire siremol/sire-generate-wrappers +docker run -it -v /path/to/sire:/root/sire openbiosim/sire-generate-wrappers:arm64 ``` -This will make your Sire directory (in `/path/to/Sire`) available in the -container as `/root/Sire`. You can now generate wrappers in the -container that will write directly to your real local Sire directory +This will make your sire directory (in `/path/to/sire`) available in the +container as `/root/sire`. You can now generate wrappers in the +container that will write directly to your real local sire directory (and so can be compiled, tested and pushed to GitHub from there). Once in the container, you need to run `unpack_headers` to unpack the @@ -114,14 +128,14 @@ headers. (base) root:~# unpack_headers ``` -You can now change into the Sire directory and generate wrappers as you +You can now change into the sire directory and generate wrappers as you need, e.g. ``` -(base) root:~# cd Sire/wrapper -(base) root:~/Sire/wrapper# python AutoGenerate/scanheaders.py ~/Sire/corelib/src/libs/ . -(base) root:~/Sire/wrapper# cd Search -(base) root:~/Sire/wrapper/Search# python ../AutoGenerate/create_wrappers.py +(base) root:~# cd sire/wrapper +(base) root:~/sire/wrapper# python AutoGenerate/scanheaders.py ~/sire/corelib/src/libs/ . +(base) root:~/sire/wrapper# cd Search +(base) root:~/sire/wrapper/Search# python ../AutoGenerate/create_wrappers.py ``` would regenerate the wrappers for the `Search` module. Note that this @@ -132,26 +146,26 @@ you needing to push and pull changes via git. Be very careful doing this, as the git version in the container is not going to be the same as on your local computer. Also be careful not -to run `generate_wrappers` as this will delete your local Sire container. +to run `generate_wrappers` as this will delete your local sire container. ## Creating the sire-generate-wrappers container You only need to read here if you want to create the sire-generate-wrappers container yourself. -First, you must have a working installation on Sire +First, you must have a working installation on sire on your computer. This is needed so that we can copy the header files from this installation into -the container. We will assume that Sire is installed +the container. We will assume that sire is installed in `$HOME/sire.app`. Next, you must navigate to this directory, e.g. ``` -cd $HOME/Sire/docker/sire-generate-wrappers +cd $HOME/sire/docker/sire-generate-wrappers ``` -(assuming Sire was cloned to `$HOME/Sire`) +(assuming sire was cloned to `$HOME/sire`) Create the `includes.tar.bz2` file by running the `create_includes_tarball` script via; diff --git a/setup.py b/setup.py index 83a8c99ca..a974e2e48 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,15 @@ import shutil import glob +try: + # Find out how much memory we have in total. + # The wrappers need 4 GB per core to compile + import psutil + + total_memory_gb = psutil.virtual_memory()[0] / (1024 * 1024 * 1024) +except Exception: + total_memory_gb = None + # Debug - we need to print out all of the environment variables # for key, value in os.environ.items(): # print(f"{key}\n{value}\n") @@ -43,7 +52,7 @@ sys.path.insert(0, os.path.join(curdir, "actions")) # We need to verify that this is a Python that is part of a -# conda installation +# conda installation # Find the path to the conda or mamba executable conda_base = os.path.abspath(os.path.dirname(sys.executable)) @@ -79,9 +88,11 @@ if conda is None: conda = os.path.join(conda_bin, "conda") else: - print("Cannot find a 'python' binary in directory '%s'. " - "Are you running this script using the python executable " - "from a valid miniconda or anaconda installation?" % conda_base) + print( + "Cannot find a 'python' binary in directory '%s'. " + "Are you running this script using the python executable " + "from a valid miniconda or anaconda installation?" % conda_base + ) sys.exit(-1) @@ -136,53 +147,109 @@ def find_mamba(): def parse_args(): import argparse import multiprocessing - parser=argparse.ArgumentParser() + + parser = argparse.ArgumentParser() ncores = multiprocessing.cpu_count() - if ncores % 2 == 0: - npycores = int(ncores / 2) + if total_memory_gb is None: + # it is safest to half the number of python build cores + if ncores % 2 == 0: + npycores = int(ncores / 2) + else: + npycores = int((ncores + 1) / 2) else: - npycores = int((ncores + 1) / 2) - - parser.add_argument("-C", "--corelib", action="append", nargs=1, - metavar=("PARAMETER=VALUE",), default=[], - help="pass CMake definitions for corelib") - parser.add_argument("-W", "--wrapper", action="append", nargs=1, - metavar=("PARAMETER=VALUE",), default=[], - help="pass CMake definitions for wrapper") - parser.add_argument("-G", "--generator", action="append", nargs=1, - metavar=("GENERATOR",), default=[], - help="pass CMake generator") - parser.add_argument("-n", "--ncores", action="store", type=int, nargs=1, - metavar=("N_CORES",), default=[ncores], + # we need at least 4 GB RAM per core + npycores = min(ncores, int(total_memory_gb / 4)) + + if npycores < 1: + npycores = 1 + + parser.add_argument( + "-C", + "--corelib", + action="append", + nargs=1, + metavar=("PARAMETER=VALUE",), + default=[], + help="pass CMake definitions for corelib", + ) + parser.add_argument( + "-W", + "--wrapper", + action="append", + nargs=1, + metavar=("PARAMETER=VALUE",), + default=[], + help="pass CMake definitions for wrapper", + ) + parser.add_argument( + "-G", + "--generator", + action="append", + nargs=1, + metavar=("GENERATOR",), + default=[], + help="pass CMake generator", + ) + parser.add_argument( + "-n", + "--ncores", + action="store", + type=int, + nargs=1, + metavar=("N_CORES",), + default=[ncores], help="Number of CPU cores used for compiling corelib " - "(defaults to all available on the current system)") - parser.add_argument("-N", "--npycores", action="store", type=int, nargs=1, - metavar=("N_PYTHON_CORES",), default=[npycores], + "(defaults to all available on the current system)", + ) + parser.add_argument( + "-N", + "--npycores", + action="store", + type=int, + nargs=1, + metavar=("N_PYTHON_CORES",), + default=[npycores], help="Number of CPU cores used for compiling Python wrappers " - "(defaults to the number of CPU cores used for compiling corelib)") - parser.add_argument("--install-bss-deps", action="store_true", default=False, + "(defaults to the number of CPU cores used for compiling corelib)", + ) + parser.add_argument( + "--install-bss-deps", + action="store_true", + default=False, help="Install BioSimSpace's dependencies too. This helps ensure " - "compatibility between Sire's and BioSimSpace's dependencies.") - parser.add_argument("--skip-deps", action="store_true", default=False, + "compatibility between Sire's and BioSimSpace's dependencies.", + ) + parser.add_argument( + "--skip-deps", + action="store_true", + default=False, help="Skip the installation of the dependencies (only use if you know " - "that they are already installed)") - parser.add_argument("--skip-build", action="store_true", default=False, + "that they are already installed)", + ) + parser.add_argument( + "--skip-build", + action="store_true", + default=False, help="Skip the build of the C++ code (only use if you know that " - "the C++ code is already built)") - parser.add_argument("action", nargs="*", + "the C++ code is already built)", + ) + parser.add_argument( + "action", + nargs="*", help="Should be one of 'install_requires', 'build', 'install' or 'install_module'.\n" - "\n [install_requires] : Just install the conda dependencies.\n" - " [build] : 'install_requires' plus compile and install corelib, and just compile the wrappers.\n" - " [install] : 'build' plus install the wrappers and install the module.\n" - " [install_module] : Just install the module (no compilation or conda dependencies)." - ) + "\n [install_requires] : Just install the conda dependencies.\n" + " [build] : 'install_requires' plus compile and install corelib, and just compile the wrappers.\n" + " [install] : 'build' plus install the wrappers and install the module.\n" + " [install_module] : Just install the module (no compilation or conda dependencies).", + ) return parser.parse_args() _installed_deps = None + def _get_installed(conda: str): """Return the list of installed conda dependencies""" global _installed_deps @@ -215,6 +282,7 @@ def _add_to_dependencies(dependencies, lines): _is_conda_prepped = False + def conda_install(dependencies, install_bss_reqs=False): """Install the passed list of dependencies using conda""" @@ -224,7 +292,9 @@ def conda_install(dependencies, install_bss_reqs=False): if not _is_conda_prepped: if install_bss_reqs: - cmd = "%s config --prepend channels openbiosim/label/dev" % conda_exe + cmd = ( + "%s config --prepend channels openbiosim/label/dev" % conda_exe + ) print("Activating openbiosim channel channel using: '%s'" % cmd) status = subprocess.run(cmd.split()) if status.returncode != 0: @@ -253,7 +323,7 @@ def conda_install(dependencies, install_bss_reqs=False): else: conda_install = [mamba, "install", "--yes"] - dependencies = [f"\"{dep}\"" for dep in dependencies] + dependencies = [f'"{dep}"' for dep in dependencies] cmd = [*conda_install, *dependencies] print("\nInstalling packages using: '%s'" % " ".join(cmd)) @@ -277,16 +347,20 @@ def conda_install(dependencies, install_bss_reqs=False): def install_requires(install_bss_reqs=False): """Installs all of the dependencies. This can safely be called - multiple times, as it will cache the result to prevent future - installs taking too long + multiple times, as it will cache the result to prevent future + installs taking too long """ print(f"Installing requirements for {platform_string}") if not os.path.exists(conda): - print("\nSire can only be installed into a conda or miniconda environment.") - print("Please install conda, miniconda, miniforge or similar, then " - "activate the conda environment, then rerun this installation " - "script.") + print( + "\nSire can only be installed into a conda or miniconda environment." + ) + print( + "Please install conda, miniconda, miniforge or similar, then " + "activate the conda environment, then rerun this installation " + "script." + ) sys.exit(-1) # install mamba if it doesn't exist already @@ -308,7 +382,9 @@ def install_requires(install_bss_reqs=False): from parse_requirements import parse_requirements except ImportError as e: print("\n\n[ERROR] ** You need to install pip-requirements-parser") - print("Run `conda install -c conda-forge pip-requirements-parser\n\n") + print( + "Run `conda install -c conda-forge pip-requirements-parser\n\n" + ) raise e reqs = parse_requirements("requirements.txt") @@ -323,27 +399,32 @@ def install_requires(install_bss_reqs=False): def add_default_cmake_defs(cmake_defs, ncores): - for a in ("ANACONDA_BASE=%s" % conda_base.replace("\\", "/"), - "BUILD_NCORES=%s" % ncores): + for a in ( + "ANACONDA_BASE=%s" % conda_base.replace("\\", "/"), + "BUILD_NCORES=%s" % ncores, + ): found = False for d in cmake_defs: - if (a in d[0]): + if a in d[0]: found = True break - if (not found): + if not found: cmake_defs.append([a]) if is_macos: - # don't compile with AVX as the resulting binaries won't + # don't compile with AVX as the resulting binaries won't # work on M1 macs cmake_defs.append(["SIRE_DISABLE_AVX=ON"]) cmake_defs.append(["SIRE_DISABLE_AVX512F=ON"]) -def make_cmd(ncores, install = False): +def make_cmd(ncores, install=False): if is_windows: action = "INSTALL" if install else "ALL_BUILD" - make_args = "%s -- /m:%s /p:Configuration=Release /p:Platform=x64" % (action, ncores) + make_args = "%s -- /m:%s /p:Configuration=Release /p:Platform=x64" % ( + action, + ncores, + ) else: action = "install" if install else "all" make_args = "%s -- VERBOSE=1 -j %s" % (action, ncores) @@ -360,7 +441,10 @@ def _get_build_ext(): else: ext = "" - return os.path.basename(conda_base.replace(" ", "_").replace(".", "_")) + ext + return ( + os.path.basename(conda_base.replace(" ", "_").replace(".", "_")) + + ext + ) def _get_bin_dir(): @@ -375,12 +459,11 @@ def _get_bin_dir(): return conda_bin -def build(ncores: int = 1, npycores: int = 1, - coredefs=[], pydefs=[]): +def build(ncores: int = 1, npycores: int = 1, coredefs=[], pydefs=[]): print("\nCompiling the C++ code") - CC=None - CXX=None + CC = None + CXX = None cmake = "cmake" @@ -410,8 +493,12 @@ def build(ncores: int = 1, npycores: int = 1, print(f"{CC} => {CC_bin}") if CXX_bin is None or CC_bin is None: - print("Cannot find the compilers requested by conda-build in the PATH") - print("Please check that the compilers are installed and available.") + print( + "Cannot find the compilers requested by conda-build in the PATH" + ) + print( + "Please check that the compilers are installed and available." + ) sys.exit(-1) # use the full paths, in case CMake struggles @@ -481,29 +568,36 @@ def build(ncores: int = 1, npycores: int = 1, status = subprocess.run([cmake, "."]) else: # this is the first time we are running cmake - sourcedir = os.path.join(os.path.dirname(os.path.dirname( - os.getcwd())), "corelib") + sourcedir = os.path.join( + os.path.dirname(os.path.dirname(os.getcwd())), "corelib" + ) if not os.path.exists(os.path.join(sourcedir, "CMakeLists.txt")): - print("SOMETHING IS WRONG. There is no file %s" % os.path.join(sourcedir, "CMakeLists.txt")) + print( + "SOMETHING IS WRONG. There is no file %s" + % os.path.join(sourcedir, "CMakeLists.txt") + ) sys.exit(-1) for a in ("NetCDF_ROOT_DIR", "OPENMM_ROOT_DIR"): for i, d in enumerate(args.corelib): - if (a in d[0]): + if a in d[0]: v = args.corelib.pop(i)[0] - if (not a in os.environ): + if not a in os.environ: os.environ[a] = v.split("=")[-1] add_default_cmake_defs(args.corelib, ncores) - cmake_cmd = [cmake, *sum([["-D", d[0]] for d in args.corelib], []), - *sum([["-G", g[0]] for g in args.generator], []), - sourcedir] + cmake_cmd = [ + cmake, + *sum([["-D", d[0]] for d in args.corelib], []), + *sum([["-G", g[0]] for g in args.generator], []), + sourcedir, + ] - if (CC): + if CC: os.environ["CC"] = CC - if (CXX): + if CXX: os.environ["CXX"] = CXX print(" ".join(cmake_cmd)) @@ -535,7 +629,9 @@ def build(ncores: int = 1, npycores: int = 1, # Compile and install, as need to install to compile the wrappers make_args = make_cmd(ncores, True) - print("NOW RUNNING \"%s\" --build . --target %s" % (cmake, " ".join(make_args))) + print( + 'NOW RUNNING "%s" --build . --target %s' % (cmake, " ".join(make_args)) + ) sys.stdout.flush() status = subprocess.run([cmake, "--build", ".", "--target", *make_args]) @@ -568,18 +664,25 @@ def build(ncores: int = 1, npycores: int = 1, status = subprocess.run([cmake, "."]) else: # this is the first time we are running cmake - sourcedir = os.path.join(os.path.dirname(os.path.dirname( - os.getcwd())), "wrapper") + sourcedir = os.path.join( + os.path.dirname(os.path.dirname(os.getcwd())), "wrapper" + ) if not os.path.exists(os.path.join(sourcedir, "CMakeLists.txt")): - print("SOMETHING IS WRONG. There is no file %s" % os.path.join(sourcedir, "CMakeLists.txt")) + print( + "SOMETHING IS WRONG. There is no file %s" + % os.path.join(sourcedir, "CMakeLists.txt") + ) sys.exit(-1) add_default_cmake_defs(args.wrapper, npycores) - cmake_cmd = [cmake, *sum([["-D", d[0]] for d in args.wrapper], []), - *sum([["-G", g[0]] for g in args.generator], []), - sourcedir] + cmake_cmd = [ + cmake, + *sum([["-D", d[0]] for d in args.wrapper], []), + *sum([["-G", g[0]] for g in args.generator], []), + sourcedir, + ] print(" ".join(cmake_cmd)) sys.stdout.flush() @@ -592,7 +695,9 @@ def build(ncores: int = 1, npycores: int = 1, # Just compile the wrappers make_args = make_cmd(npycores, False) - print("NOW RUNNING \"%s\" --build . --target %s" % (cmake, " ".join(make_args))) + print( + 'NOW RUNNING "%s" --build . --target %s' % (cmake, " ".join(make_args)) + ) sys.stdout.flush() status = subprocess.run([cmake, "--build", ".", "--target", *make_args]) @@ -636,17 +741,24 @@ def install_module(ncores: int = 1): status = subprocess.run([cmake, "."]) else: # this is the first time we are running cmake - sourcedir = os.path.join(os.path.dirname(os.path.dirname( - os.getcwd())), "src", "sire") + sourcedir = os.path.join( + os.path.dirname(os.path.dirname(os.getcwd())), "src", "sire" + ) if not os.path.exists(os.path.join(sourcedir, "CMakeLists.txt")): - print("SOMETHING IS WRONG. There is no file %s" % os.path.join(sourcedir, "CMakeLists.txt")) + print( + "SOMETHING IS WRONG. There is no file %s" + % os.path.join(sourcedir, "CMakeLists.txt") + ) sys.exit(-1) add_default_cmake_defs(args.wrapper, ncores) - cmake_cmd = [cmake, *sum([["-D", d[0]] for d in args.wrapper], []), - *sum([["-G", g[0]] for g in args.generator], []), - sourcedir] + cmake_cmd = [ + cmake, + *sum([["-D", d[0]] for d in args.wrapper], []), + *sum([["-G", g[0]] for g in args.generator], []), + sourcedir, + ] print(" ".join(cmake_cmd)) sys.stdout.flush() status = subprocess.run(cmake_cmd) @@ -658,7 +770,9 @@ def install_module(ncores: int = 1): make_args = make_cmd(ncores, True) # Now that cmake has run, we can compile and install wrapper - print("NOW RUNNING \"%s\" --build . --target %s" % (cmake, " ".join(make_args))) + print( + 'NOW RUNNING "%s" --build . --target %s' % (cmake, " ".join(make_args)) + ) sys.stdout.flush() status = subprocess.run([cmake, "--build", ".", "--target", *make_args]) @@ -698,7 +812,9 @@ def install(ncores: int = 1, npycores: int = 1): # Now install the wrappers make_args = make_cmd(npycores, True) - print("NOW RUNNING \"%s\" --build . --target %s" % (cmake, " ".join(make_args))) + print( + 'NOW RUNNING "%s" --build . --target %s' % (cmake, " ".join(make_args)) + ) sys.stdout.flush() status = subprocess.run([cmake, "--build", ".", "--target", *make_args]) @@ -723,16 +839,22 @@ def install(ncores: int = 1, npycores: int = 1): action = args.action[0] if is_windows and (args.generator is None or len(args.generator) == 0): - #args.generator = [["Visual Studio 17 2022"]] - args.generator = [["Visual Studio 15 2017 Win64"]] # preferred VC version for conda + # args.generator = [["Visual Studio 17 2022"]] + args.generator = [ + ["Visual Studio 15 2017 Win64"] + ] # preferred VC version for conda if action == "install": if not (args.skip_deps or args.skip_build): install_requires(install_bss_reqs=install_bss) if not args.skip_build: - build(ncores=args.ncores[0], npycores=args.npycores[0], - coredefs=args.corelib, pydefs=args.wrapper) + build( + ncores=args.ncores[0], + npycores=args.npycores[0], + coredefs=args.corelib, + pydefs=args.wrapper, + ) install(ncores=args.ncores[0], npycores=args.npycores[0]) @@ -740,8 +862,12 @@ def install(ncores: int = 1, npycores: int = 1): if not args.skip_deps: install_requires(install_bss_reqs=install_bss) - build(ncores=args.ncores[0], npycores=args.npycores[0], - coredefs=args.corelib, pydefs=args.wrapper) + build( + ncores=args.ncores[0], + npycores=args.npycores[0], + coredefs=args.corelib, + pydefs=args.wrapper, + ) elif action == "install_requires": install_requires(install_bss_reqs=install_bss) @@ -750,5 +876,7 @@ def install(ncores: int = 1, npycores: int = 1): install_module(ncores=args.ncores[0]) else: - print(f"Unrecognised action '{action}'. Please use 'install_requires', " - "'build', 'install' or 'install_module'") + print( + f"Unrecognised action '{action}'. Please use 'install_requires', " + "'build', 'install' or 'install_module'" + ) diff --git a/src/sire/mol/__init__.py b/src/sire/mol/__init__.py index 8ce6270ca..749d4eaba 100644 --- a/src/sire/mol/__init__.py +++ b/src/sire/mol/__init__.py @@ -1355,7 +1355,9 @@ def _total_energy(obj, other=None, map=None): elif other is None: return calculate_energy(mols.molecules(), map=map) else: - return calculate_energy(mols.molecules(), _to_molecules(other), map=map) + return calculate_energy( + mols.molecules(), _to_molecules(other), map=map + ) Atom.energy = _atom_energy @@ -1404,5 +1406,60 @@ def _total_energy(obj, other=None, map=None): SelectorM_Segment_.view = _viewfunc SelectorM_CutGroup_.view = _viewfunc +if not hasattr(SelectorMol, "__orig__find__"): + + def __find__(obj, views): + """ + Find the index(es) of the passed view(s) in this container. + This returns a single index if a single view is passed, + or a list of indexes if multiple views are passed + (in the same order as the passed views). + + This raises an IndexError if any of the views are + not in this container. + """ + matches = obj.__orig__find__(views) + + if matches is None: + raise IndexError("Cannot find the passed view in the container.") + + if views.is_selector(): + if len(matches) != len(views): + raise IndexError( + "Could not find all of the passed views " + "in the container. We only found " + f"{len(matches)} of the required " + f"{len(views)}." + ) + + return matches + else: + if len(matches) != 1: + raise IndexError( + "We matched too many indexes? " + f"{matches}. Only expected to match one?" + ) + + return matches[0] + + def __fix__find(CLASS): + CLASS.__orig__find__ = CLASS.find + CLASS.find = __find__ + + for C in [ + Selector_Atom_, + Selector_Residue_, + Selector_Chain_, + Selector_CutGroup_, + Selector_Segment_, + SelectorMol, + SelectorM_Atom_, + SelectorM_Residue_, + SelectorM_Chain_, + SelectorM_CutGroup_, + SelectorM_Segment_, + ]: + __fix__find(C) + # Remove some temporary variables del C diff --git a/src/sire/search/__init__.py b/src/sire/search/__init__.py index 776a7351a..fa45724b7 100644 --- a/src/sire/search/__init__.py +++ b/src/sire/search/__init__.py @@ -1,5 +1,10 @@ __all__ = [ "approx_equal", + "approx_greater", + "approx_greater_equal", + "approx_less", + "approx_less_equal", + "approx_not_equal", "delete_all_tokens", "delete_token", "get_approx_epsilon", @@ -19,6 +24,11 @@ from ..legacy.Search import ( approx_equal, + approx_greater, + approx_greater_equal, + approx_less, + approx_less_equal, + approx_not_equal, set_approx_epsilon, get_approx_epsilon, get_min_protein_residues, diff --git a/src/sire/system/_system.py b/src/sire/system/_system.py index 5948ced7e..20c00d2a7 100644 --- a/src/sire/system/_system.py +++ b/src/sire/system/_system.py @@ -85,6 +85,10 @@ def num_molecules(self): """Return the number of molecules in this System""" return self._system.num_molecules() + def find(self, views): + """Return the index(es) of the molecule(s) that are in `views`""" + return self.molecules().find(views) + def names(self): """Return the names of all of the molecules in this System""" return self.molecules().names() diff --git a/src/sire/units/__init__.py b/src/sire/units/__init__.py index 231bacb0c..8a44875d3 100644 --- a/src/sire/units/__init__.py +++ b/src/sire/units/__init__.py @@ -9,23 +9,147 @@ "set_quantity_unit", "set_si_units", "set_time_unit", + "GeneralUnit", + "akma_time", + "akma_velocity", + "amp", + "angle_minute", + "angle_minutes", + "angle_second", + "angle_seconds", "angstrom", + "angstroms", + "angstrom2", + "angstrom3", + "angstroms_per_fs", + "atm", + "atomic_mass_constant", + "bar", + "bohr_radii", + "c", + "cal", + "cal_per_mol", "celsius", + "centimeter", + "centimeters", + "circumference", + "convert", + "coulomb", + "coulomb_per_mol", + "day", + "degree", "degrees", + "e_charge", + "electron_mass", + "epsilon0", "fahrenheit", "farad", + "faraday", + "feet", + "femtogram", "femtosecond", + "fg_per_mol", + "fortnight", + "four_pi_eps0", + "g_accel", "g_per_mol", + "gasr", + "grad", + "gradian", + "gradians", + "gram", + "gon", + "G_newton", + "h_planck", + "h_slash", + "hartree", + "hour", + "hundredweight", + "inch", + "int_cal", + "int_cal_per_mol", + "int_kcal", + "int_kcal_per_mol", + "joule", + "J_per_mol", + "k_boltz", + "kcal", "kcal_per_mol", + "kelvin", + "kilogram", + "kilojoule", + "kilometer", + "kilometers", + "kilometers_per_hour", + "kg_per_mol", "kJ_per_mol", - "mod_electron", + "kph", + "megajoule", "meter", + "meter2", + "meter3", + "meters", + "meters_per_second", + "mg_per_mol", + "microgram", + "micrometer", + "microsecond", + "miles", + "miles_per_hour", + "milligram", + "millimeter", + "millimeters", + "millisecond", + "minute", + "mmHg", + "mod_electron", + "molar_volume", + "mole", + "mph", + "mu0", + "MJ_per_mol", + "nanogram", "nanometer", + "nanometers", "nanometer2", "nanosecond", + "neutron_mass", + "newton", + "ng_per_mol", + "octant", + "octants", + "one_over_four_pi_eps0", + "ounce", + "pascal", + "pg_per_mol", + "picogram", "picometer", + "picometers", + "picometer2", + "picometer3", "picosecond", + "pound", + "proton_mass", + "psi", + "quadrant", + "quadrants", + "radian", "radians", + "revolution", + "revolutions", + "revs", + "second", + "sextant", + "sextants", + "stone", + "tonne", + "tonne_per_mol", + "ug_per_mol", + "volt", + "watt", + "watt_per_mol", + "week", + "yards", ] from ..legacy import Units as _Units @@ -33,33 +157,146 @@ from .. import use_new_api as _use_new_api from ..legacy.Units import ( + akma_time, + akma_velocity, + amp, + angle_minute, + angle_minutes, + angle_second, + angle_seconds, angstrom, + angstroms, + angstrom2, + angstrom3, + angstroms_per_fs, + atm, + atomic_mass_constant, + bar, + bohr_radii, + c, cal, + cal_per_mol, celsius, + centimeter, + centimeters, + circumference, convert, + coulomb, + coulomb_per_mol, + day, + degree, degrees, + e_charge, + electron_mass, + epsilon0, fahrenheit, farad, + faraday, + feet, + femtogram, femtosecond, + fg_per_mol, + fortnight, + four_pi_eps0, + g_accel, g_per_mol, + gasr, + grad, + gradian, + gradians, gram, - joule, - mod_electron, - meter, + gon, + G_newton, + h_planck, + h_slash, + hartree, + hour, + hundredweight, + inch, int_cal, + int_cal_per_mol, int_kcal, + int_kcal_per_mol, + joule, + J_per_mol, + k_boltz, kcal, kcal_per_mol, + kelvin, kilogram, kilojoule, + kilometer, + kilometers, + kilometers_per_hour, + kg_per_mol, kJ_per_mol, + kph, + megajoule, + meter, + meter2, + meter3, + meters, + meters_per_second, + mg_per_mol, + microgram, + micrometer, + microsecond, + miles, + miles_per_hour, + milligram, + millimeter, + millimeters, + millisecond, + minute, + mmHg, + mod_electron, + molar_volume, mole, + mph, + mu0, + MJ_per_mol, + nanogram, nanometer, + nanometers, nanometer2, nanosecond, + neutron_mass, + newton, + ng_per_mol, + octant, + octants, + one_over_four_pi_eps0, + ounce, + pascal, + pg_per_mol, + picogram, picometer, + picometers, + picometer2, + picometer3, picosecond, + pound, + proton_mass, + psi, + quadrant, + quadrants, + radian, radians, + revolution, + revolutions, + revs, + second, + sextant, + sextants, + stone, + tonne, + tonne_per_mol, + ug_per_mol, + volt, + watt, + watt_per_mol, + week, + yards, GeneralUnit, ) diff --git a/tests/mol/test_find.py b/tests/mol/test_find.py new file mode 100644 index 000000000..1e0d996ac --- /dev/null +++ b/tests/mol/test_find.py @@ -0,0 +1,31 @@ +import pytest + + +def test_find(ala_mols): + + mols = ala_mols + + assert mols.atoms().find(mols.atoms()[0]) == 0 + + assert mols.atoms().find(mols.atoms()[1000]) == 1000 + + assert mols.atoms().find(mols.atoms()[10:100]) == list(range(10, 100)) + + idxs = mols.atoms().find(mols["element C"]) + + assert len(idxs) == len(mols["element C"]) + + for idx in idxs: + assert mols.atoms()[idx].element().num_protons() == 6 + + assert mols.residues().find(mols["resname ALA"]) == 1 + + assert mols.find(mols[600]) == 600 + + assert mols.find(mols[3:50:3]) == list(range(3, 50, 3)) + + with pytest.raises(IndexError): + mols[1:].find(mols[0]) + + with pytest.raises(IndexError): + mols[1:].atoms().find(mols["element C"]) diff --git a/wrapper/Mol/Atom.pypp.cpp b/wrapper/Mol/Atom.pypp.cpp index 61327a54a..4eb4a032f 100644 --- a/wrapper/Mol/Atom.pypp.cpp +++ b/wrapper/Mol/Atom.pypp.cpp @@ -94,6 +94,8 @@ namespace bp = boost::python; #include "atomproperty.hpp" +#include "SireMol/core.h" + const SireMM::LJParameter& get_Metadata_SireMM_AtomLJs_function1(const SireMol::Atom &atom, const QString &metakey){ return atom.metadata< SireMM::LJParameter >(metakey); } diff --git a/wrapper/Mol/Bead.pypp.cpp b/wrapper/Mol/Bead.pypp.cpp index bdac5958c..fe1f04f04 100644 --- a/wrapper/Mol/Bead.pypp.cpp +++ b/wrapper/Mol/Bead.pypp.cpp @@ -42,6 +42,8 @@ namespace bp = boost::python; #include "beadproperty.hpp" +#include "SireMol/core.h" + const QString& get_Metadata_SireMol_BeadStringProperty_function1(const SireMol::Bead &atom, const QString &metakey){ return atom.metadata< QString >(metakey); } diff --git a/wrapper/Mol/Chain.pypp.cpp b/wrapper/Mol/Chain.pypp.cpp index 9ce0e5144..1ce7097a8 100644 --- a/wrapper/Mol/Chain.pypp.cpp +++ b/wrapper/Mol/Chain.pypp.cpp @@ -39,6 +39,8 @@ namespace bp = boost::python; #include "chainproperty.hpp" +#include "SireMol/core.h" + const QString& get_Metadata_SireMol_ChainStringProperty_function1(const SireMol::Chain &atom, const QString &metakey){ return atom.metadata< QString >(metakey); } diff --git a/wrapper/Mol/CutGroup.pypp.cpp b/wrapper/Mol/CutGroup.pypp.cpp index e19cd758a..9303a025d 100644 --- a/wrapper/Mol/CutGroup.pypp.cpp +++ b/wrapper/Mol/CutGroup.pypp.cpp @@ -40,6 +40,8 @@ namespace bp = boost::python; #include "cgproperty.hpp" +#include "SireMol/core.h" + const QString& get_Metadata_SireMol_CGStringProperty_function1(const SireMol::CutGroup &atom, const QString &metakey){ return atom.metadata< QString >(metakey); } diff --git a/wrapper/Mol/Residue.pypp.cpp b/wrapper/Mol/Residue.pypp.cpp index 9983880d5..430476f5d 100644 --- a/wrapper/Mol/Residue.pypp.cpp +++ b/wrapper/Mol/Residue.pypp.cpp @@ -41,6 +41,8 @@ namespace bp = boost::python; #include "resproperty.hpp" +#include "SireMol/core.h" + const QString& get_Metadata_SireMol_ResStringProperty_function1(const SireMol::Residue &atom, const QString &metakey){ return atom.metadata< QString >(metakey); } diff --git a/wrapper/Mol/Segment.pypp.cpp b/wrapper/Mol/Segment.pypp.cpp index 0858959d5..8e6dbbeed 100644 --- a/wrapper/Mol/Segment.pypp.cpp +++ b/wrapper/Mol/Segment.pypp.cpp @@ -36,6 +36,8 @@ namespace bp = boost::python; #include "segproperty.hpp" +#include "SireMol/core.h" + const QString& get_Metadata_SireMol_SegStringProperty_function1(const SireMol::Segment &atom, const QString &metakey){ return atom.metadata< QString >(metakey); } diff --git a/wrapper/Mol/SelectorM_Atom_.pypp.cpp b/wrapper/Mol/SelectorM_Atom_.pypp.cpp index 8c82a8db6..5595754ae 100644 --- a/wrapper/Mol/SelectorM_Atom_.pypp.cpp +++ b/wrapper/Mol/SelectorM_Atom_.pypp.cpp @@ -579,6 +579,48 @@ void register_SelectorM_Atom__class(){ , bp::release_gil_policy() , "" ); + } + { //::SireMol::SelectorM< SireMol::Atom >::find + + typedef SireMol::SelectorM< SireMol::Atom > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::Atom >::*find_function_type)( ::SireMol::Atom const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::Atom >::find ); + + SelectorM_Atom__exposer.def( + "find" + , find_function_value + , ( bp::arg("view") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::SelectorM< SireMol::Atom >::find + + typedef SireMol::SelectorM< SireMol::Atom > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::Atom >::*find_function_type)( ::SireMol::Selector< SireMol::Atom > const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::Atom >::find ); + + SelectorM_Atom__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::SelectorM< SireMol::Atom >::find + + typedef SireMol::SelectorM< SireMol::Atom > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::Atom >::*find_function_type)( ::SireMol::SelectorM< SireMol::Atom > const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::Atom >::find ); + + SelectorM_Atom__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + } { //::SireMol::SelectorM< SireMol::Atom >::indexes diff --git a/wrapper/Mol/SelectorM_Chain_.pypp.cpp b/wrapper/Mol/SelectorM_Chain_.pypp.cpp index a07980d3c..b3a917790 100644 --- a/wrapper/Mol/SelectorM_Chain_.pypp.cpp +++ b/wrapper/Mol/SelectorM_Chain_.pypp.cpp @@ -579,6 +579,48 @@ void register_SelectorM_Chain__class(){ , bp::release_gil_policy() , "" ); + } + { //::SireMol::SelectorM< SireMol::Chain >::find + + typedef SireMol::SelectorM< SireMol::Chain > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::Chain >::*find_function_type)( ::SireMol::Chain const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::Chain >::find ); + + SelectorM_Chain__exposer.def( + "find" + , find_function_value + , ( bp::arg("view") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::SelectorM< SireMol::Chain >::find + + typedef SireMol::SelectorM< SireMol::Chain > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::Chain >::*find_function_type)( ::SireMol::Selector< SireMol::Chain > const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::Chain >::find ); + + SelectorM_Chain__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::SelectorM< SireMol::Chain >::find + + typedef SireMol::SelectorM< SireMol::Chain > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::Chain >::*find_function_type)( ::SireMol::SelectorM< SireMol::Chain > const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::Chain >::find ); + + SelectorM_Chain__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + } { //::SireMol::SelectorM< SireMol::Chain >::indexes diff --git a/wrapper/Mol/SelectorM_CutGroup_.pypp.cpp b/wrapper/Mol/SelectorM_CutGroup_.pypp.cpp index 33161f3bd..2cb0a019b 100644 --- a/wrapper/Mol/SelectorM_CutGroup_.pypp.cpp +++ b/wrapper/Mol/SelectorM_CutGroup_.pypp.cpp @@ -579,6 +579,48 @@ void register_SelectorM_CutGroup__class(){ , bp::release_gil_policy() , "" ); + } + { //::SireMol::SelectorM< SireMol::CutGroup >::find + + typedef SireMol::SelectorM< SireMol::CutGroup > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::CutGroup >::*find_function_type)( ::SireMol::CutGroup const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::CutGroup >::find ); + + SelectorM_CutGroup__exposer.def( + "find" + , find_function_value + , ( bp::arg("view") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::SelectorM< SireMol::CutGroup >::find + + typedef SireMol::SelectorM< SireMol::CutGroup > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::CutGroup >::*find_function_type)( ::SireMol::Selector< SireMol::CutGroup > const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::CutGroup >::find ); + + SelectorM_CutGroup__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::SelectorM< SireMol::CutGroup >::find + + typedef SireMol::SelectorM< SireMol::CutGroup > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::CutGroup >::*find_function_type)( ::SireMol::SelectorM< SireMol::CutGroup > const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::CutGroup >::find ); + + SelectorM_CutGroup__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + } { //::SireMol::SelectorM< SireMol::CutGroup >::indexes diff --git a/wrapper/Mol/SelectorM_Residue_.pypp.cpp b/wrapper/Mol/SelectorM_Residue_.pypp.cpp index 782ca3bc1..f10148a37 100644 --- a/wrapper/Mol/SelectorM_Residue_.pypp.cpp +++ b/wrapper/Mol/SelectorM_Residue_.pypp.cpp @@ -579,6 +579,48 @@ void register_SelectorM_Residue__class(){ , bp::release_gil_policy() , "" ); + } + { //::SireMol::SelectorM< SireMol::Residue >::find + + typedef SireMol::SelectorM< SireMol::Residue > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::Residue >::*find_function_type)( ::SireMol::Residue const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::Residue >::find ); + + SelectorM_Residue__exposer.def( + "find" + , find_function_value + , ( bp::arg("view") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::SelectorM< SireMol::Residue >::find + + typedef SireMol::SelectorM< SireMol::Residue > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::Residue >::*find_function_type)( ::SireMol::Selector< SireMol::Residue > const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::Residue >::find ); + + SelectorM_Residue__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::SelectorM< SireMol::Residue >::find + + typedef SireMol::SelectorM< SireMol::Residue > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::Residue >::*find_function_type)( ::SireMol::SelectorM< SireMol::Residue > const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::Residue >::find ); + + SelectorM_Residue__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + } { //::SireMol::SelectorM< SireMol::Residue >::indexes diff --git a/wrapper/Mol/SelectorM_Segment_.pypp.cpp b/wrapper/Mol/SelectorM_Segment_.pypp.cpp index 2b6984953..76e147759 100644 --- a/wrapper/Mol/SelectorM_Segment_.pypp.cpp +++ b/wrapper/Mol/SelectorM_Segment_.pypp.cpp @@ -579,6 +579,48 @@ void register_SelectorM_Segment__class(){ , bp::release_gil_policy() , "" ); + } + { //::SireMol::SelectorM< SireMol::Segment >::find + + typedef SireMol::SelectorM< SireMol::Segment > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::Segment >::*find_function_type)( ::SireMol::Segment const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::Segment >::find ); + + SelectorM_Segment__exposer.def( + "find" + , find_function_value + , ( bp::arg("view") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::SelectorM< SireMol::Segment >::find + + typedef SireMol::SelectorM< SireMol::Segment > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::Segment >::*find_function_type)( ::SireMol::Selector< SireMol::Segment > const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::Segment >::find ); + + SelectorM_Segment__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::SelectorM< SireMol::Segment >::find + + typedef SireMol::SelectorM< SireMol::Segment > exported_class_t; + typedef ::QList< long long > ( ::SireMol::SelectorM< SireMol::Segment >::*find_function_type)( ::SireMol::SelectorM< SireMol::Segment > const & ) const; + find_function_type find_function_value( &::SireMol::SelectorM< SireMol::Segment >::find ); + + SelectorM_Segment__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + } { //::SireMol::SelectorM< SireMol::Segment >::indexes diff --git a/wrapper/Mol/SelectorMol.pypp.cpp b/wrapper/Mol/SelectorMol.pypp.cpp index 69de8f0ce..5a3a75ad2 100644 --- a/wrapper/Mol/SelectorMol.pypp.cpp +++ b/wrapper/Mol/SelectorMol.pypp.cpp @@ -474,6 +474,32 @@ void register_SelectorMol_class(){ , bp::release_gil_policy() , "" ); + } + { //::SireMol::SelectorMol::find + + typedef ::QList< long long > ( ::SireMol::SelectorMol::*find_function_type)( ::SireMol::Molecule const & ) const; + find_function_type find_function_value( &::SireMol::SelectorMol::find ); + + SelectorMol_exposer.def( + "find" + , find_function_value + , ( bp::arg("view") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::SelectorMol::find + + typedef ::QList< long long > ( ::SireMol::SelectorMol::*find_function_type)( ::SireMol::SelectorMol const & ) const; + find_function_type find_function_value( &::SireMol::SelectorMol::find ); + + SelectorMol_exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + } { //::SireMol::SelectorMol::indexes diff --git a/wrapper/Mol/Selector_Atom_.pypp.cpp b/wrapper/Mol/Selector_Atom_.pypp.cpp index 4ee98ab8c..9a5f3b2dd 100644 --- a/wrapper/Mol/Selector_Atom_.pypp.cpp +++ b/wrapper/Mol/Selector_Atom_.pypp.cpp @@ -45,6 +45,8 @@ namespace bp = boost::python; #include "atom.h" +#include "SireMol/core.h" + SireMol::Selector __copy__(const SireMol::Selector &other){ return SireMol::Selector(other); } #include "Qt/qdatastream.hpp" @@ -204,6 +206,48 @@ void register_Selector_Atom__class(){ , bp::release_gil_policy() , "" ); + } + { //::SireMol::Selector< SireMol::Atom >::find + + typedef SireMol::Selector< SireMol::Atom > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::Atom >::*find_function_type)( ::SireMol::Atom const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::Atom >::find ); + + Selector_Atom__exposer.def( + "find" + , find_function_value + , ( bp::arg("view") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::Selector< SireMol::Atom >::find + + typedef SireMol::Selector< SireMol::Atom > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::Atom >::*find_function_type)( ::SireMol::Selector< SireMol::Atom > const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::Atom >::find ); + + Selector_Atom__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::Selector< SireMol::Atom >::find + + typedef SireMol::Selector< SireMol::Atom > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::Atom >::*find_function_type)( ::SireMol::SelectorM< SireMol::Atom > const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::Atom >::find ); + + Selector_Atom__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + } { //::SireMol::Selector< SireMol::Atom >::hasMetadata diff --git a/wrapper/Mol/Selector_Chain_.pypp.cpp b/wrapper/Mol/Selector_Chain_.pypp.cpp index 69e297c92..1c7701aad 100644 --- a/wrapper/Mol/Selector_Chain_.pypp.cpp +++ b/wrapper/Mol/Selector_Chain_.pypp.cpp @@ -37,6 +37,8 @@ namespace bp = boost::python; #include "chain.h" +#include "SireMol/core.h" + SireMol::Selector __copy__(const SireMol::Selector &other){ return SireMol::Selector(other); } #include "Qt/qdatastream.hpp" @@ -196,6 +198,48 @@ void register_Selector_Chain__class(){ , bp::release_gil_policy() , "" ); + } + { //::SireMol::Selector< SireMol::Chain >::find + + typedef SireMol::Selector< SireMol::Chain > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::Chain >::*find_function_type)( ::SireMol::Chain const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::Chain >::find ); + + Selector_Chain__exposer.def( + "find" + , find_function_value + , ( bp::arg("view") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::Selector< SireMol::Chain >::find + + typedef SireMol::Selector< SireMol::Chain > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::Chain >::*find_function_type)( ::SireMol::Selector< SireMol::Chain > const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::Chain >::find ); + + Selector_Chain__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::Selector< SireMol::Chain >::find + + typedef SireMol::Selector< SireMol::Chain > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::Chain >::*find_function_type)( ::SireMol::SelectorM< SireMol::Chain > const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::Chain >::find ); + + Selector_Chain__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + } { //::SireMol::Selector< SireMol::Chain >::hasMetadata diff --git a/wrapper/Mol/Selector_CutGroup_.pypp.cpp b/wrapper/Mol/Selector_CutGroup_.pypp.cpp index d12737098..e1204ca27 100644 --- a/wrapper/Mol/Selector_CutGroup_.pypp.cpp +++ b/wrapper/Mol/Selector_CutGroup_.pypp.cpp @@ -37,6 +37,8 @@ namespace bp = boost::python; #include "cutgroup.h" +#include "SireMol/core.h" + SireMol::Selector __copy__(const SireMol::Selector &other){ return SireMol::Selector(other); } #include "Qt/qdatastream.hpp" @@ -196,6 +198,48 @@ void register_Selector_CutGroup__class(){ , bp::release_gil_policy() , "" ); + } + { //::SireMol::Selector< SireMol::CutGroup >::find + + typedef SireMol::Selector< SireMol::CutGroup > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::CutGroup >::*find_function_type)( ::SireMol::CutGroup const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::CutGroup >::find ); + + Selector_CutGroup__exposer.def( + "find" + , find_function_value + , ( bp::arg("view") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::Selector< SireMol::CutGroup >::find + + typedef SireMol::Selector< SireMol::CutGroup > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::CutGroup >::*find_function_type)( ::SireMol::Selector< SireMol::CutGroup > const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::CutGroup >::find ); + + Selector_CutGroup__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::Selector< SireMol::CutGroup >::find + + typedef SireMol::Selector< SireMol::CutGroup > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::CutGroup >::*find_function_type)( ::SireMol::SelectorM< SireMol::CutGroup > const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::CutGroup >::find ); + + Selector_CutGroup__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + } { //::SireMol::Selector< SireMol::CutGroup >::hasMetadata diff --git a/wrapper/Mol/Selector_Residue_.pypp.cpp b/wrapper/Mol/Selector_Residue_.pypp.cpp index 70ea1b1f4..ed25f804b 100644 --- a/wrapper/Mol/Selector_Residue_.pypp.cpp +++ b/wrapper/Mol/Selector_Residue_.pypp.cpp @@ -39,6 +39,8 @@ namespace bp = boost::python; #include "residue.h" +#include "SireMol/core.h" + SireMol::Selector __copy__(const SireMol::Selector &other){ return SireMol::Selector(other); } #include "Qt/qdatastream.hpp" @@ -198,6 +200,48 @@ void register_Selector_Residue__class(){ , bp::release_gil_policy() , "" ); + } + { //::SireMol::Selector< SireMol::Residue >::find + + typedef SireMol::Selector< SireMol::Residue > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::Residue >::*find_function_type)( ::SireMol::Residue const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::Residue >::find ); + + Selector_Residue__exposer.def( + "find" + , find_function_value + , ( bp::arg("view") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::Selector< SireMol::Residue >::find + + typedef SireMol::Selector< SireMol::Residue > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::Residue >::*find_function_type)( ::SireMol::Selector< SireMol::Residue > const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::Residue >::find ); + + Selector_Residue__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::Selector< SireMol::Residue >::find + + typedef SireMol::Selector< SireMol::Residue > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::Residue >::*find_function_type)( ::SireMol::SelectorM< SireMol::Residue > const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::Residue >::find ); + + Selector_Residue__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + } { //::SireMol::Selector< SireMol::Residue >::hasMetadata diff --git a/wrapper/Mol/Selector_Segment_.pypp.cpp b/wrapper/Mol/Selector_Segment_.pypp.cpp index a822286d5..3d2c08d4c 100644 --- a/wrapper/Mol/Selector_Segment_.pypp.cpp +++ b/wrapper/Mol/Selector_Segment_.pypp.cpp @@ -33,6 +33,8 @@ namespace bp = boost::python; #include "segment.h" +#include "SireMol/core.h" + SireMol::Selector __copy__(const SireMol::Selector &other){ return SireMol::Selector(other); } #include "Qt/qdatastream.hpp" @@ -192,6 +194,48 @@ void register_Selector_Segment__class(){ , bp::release_gil_policy() , "" ); + } + { //::SireMol::Selector< SireMol::Segment >::find + + typedef SireMol::Selector< SireMol::Segment > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::Segment >::*find_function_type)( ::SireMol::Segment const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::Segment >::find ); + + Selector_Segment__exposer.def( + "find" + , find_function_value + , ( bp::arg("view") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::Selector< SireMol::Segment >::find + + typedef SireMol::Selector< SireMol::Segment > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::Segment >::*find_function_type)( ::SireMol::Selector< SireMol::Segment > const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::Segment >::find ); + + Selector_Segment__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + + } + { //::SireMol::Selector< SireMol::Segment >::find + + typedef SireMol::Selector< SireMol::Segment > exported_class_t; + typedef ::QList< long long > ( ::SireMol::Selector< SireMol::Segment >::*find_function_type)( ::SireMol::SelectorM< SireMol::Segment > const & ) const; + find_function_type find_function_value( &::SireMol::Selector< SireMol::Segment >::find ); + + Selector_Segment__exposer.def( + "find" + , find_function_value + , ( bp::arg("views") ) + , bp::release_gil_policy() + , "" ); + } { //::SireMol::Selector< SireMol::Segment >::hasMetadata diff --git a/wrapper/Mol/special_code.py b/wrapper/Mol/special_code.py index 174582b7e..7a00c0cec 100644 --- a/wrapper/Mol/special_code.py +++ b/wrapper/Mol/special_code.py @@ -25,11 +25,18 @@ return_const = "bp::return_value_policy()" return_self = "bp::return_self< >()" +def fix_Selector(c): + #add in the core header files + c.add_declaration_code( "#include \"SireMol/core.h\"" ) + def fix_MolView(c, molview, props): #now add in all of the header files for header in props.dependencies(): c.add_declaration_code( "#include %s" % header ) + #add in the core header files + c.add_declaration_code( "#include \"SireMol/core.h\"" ) + #add accessor functions for all of the view properties for property in props.properties(): p = property[0] @@ -448,6 +455,12 @@ def fix_SelectResultMover(c): "SireMol::PerturbationSymbols" : fix_PerturbationSymbols, + "SireMol::Selector" : fix_Selector, + "SireMol::Selector" : fix_Selector, + "SireMol::Selector" : fix_Selector, + "SireMol::Selector" : fix_Selector, + "SireMol::Selector" : fix_Selector, + "SireMol::CGIdx" : fix_CGIdx, "SireMol::CGAtomIdx" : fix_CGAtomIdx } diff --git a/wrapper/Units/Celsius.pypp.cpp b/wrapper/Units/Celsius.pypp.cpp index e74593d53..a0ce9d00e 100644 --- a/wrapper/Units/Celsius.pypp.cpp +++ b/wrapper/Units/Celsius.pypp.cpp @@ -11,6 +11,8 @@ namespace bp = boost::python; #include "temperature.h" +#include "generalunit.h" + SireUnits::Celsius __copy__(const SireUnits::Celsius &other){ return SireUnits::Celsius(other); } #include "Helpers/str.hpp" @@ -67,13 +69,17 @@ void register_Celsius_class(){ } Celsius_exposer.def( bp::self * bp::other< double >() ); Celsius_exposer.def( bp::self * bp::other< int >() ); + Celsius_exposer.def( bp::self * bp::other< SireUnits::Dimension::GeneralUnit >() ); Celsius_exposer.def( bp::self + bp::self ); Celsius_exposer.def( bp::self + bp::other< SireUnits::Dimension::PhysUnit< 0, 0, 0, 0, 1, 0, 0 > >() ); + Celsius_exposer.def( bp::self + bp::other< SireUnits::Dimension::GeneralUnit >() ); Celsius_exposer.def( -bp::self ); Celsius_exposer.def( bp::self - bp::self ); Celsius_exposer.def( bp::self - bp::other< SireUnits::Dimension::PhysUnit< 0, 0, 0, 0, 1, 0, 0 > >() ); + Celsius_exposer.def( bp::self - bp::other< SireUnits::Dimension::GeneralUnit >() ); Celsius_exposer.def( bp::self / bp::other< double >() ); Celsius_exposer.def( bp::self / bp::other< int >() ); + Celsius_exposer.def( bp::self / bp::other< SireUnits::Dimension::GeneralUnit >() ); { //::SireUnits::Celsius::operator= typedef ::SireUnits::Celsius & ( ::SireUnits::Celsius::*assign_function_type)( ::SireUnits::Celsius const & ) ; @@ -108,6 +114,10 @@ void register_Celsius_class(){ Celsius_exposer.def( bp::other() - bp::self ); Celsius_exposer.def( bp::other() * bp::self ); Celsius_exposer.def( bp::other() / bp::self ); + Celsius_exposer.def( bp::self + bp::other() ); + Celsius_exposer.def( bp::self - bp::other() ); + Celsius_exposer.def( bp::self * bp::other() ); + Celsius_exposer.def( bp::self / bp::other() ); Celsius_exposer.def( "__copy__", &__copy__); Celsius_exposer.def( "__deepcopy__", &__copy__); Celsius_exposer.def( "clone", &__copy__); diff --git a/wrapper/Units/Fahrenheit.pypp.cpp b/wrapper/Units/Fahrenheit.pypp.cpp index d7e8a09fc..6a0712189 100644 --- a/wrapper/Units/Fahrenheit.pypp.cpp +++ b/wrapper/Units/Fahrenheit.pypp.cpp @@ -11,6 +11,8 @@ namespace bp = boost::python; #include "temperature.h" +#include "generalunit.h" + SireUnits::Fahrenheit __copy__(const SireUnits::Fahrenheit &other){ return SireUnits::Fahrenheit(other); } #include "Helpers/str.hpp" @@ -67,13 +69,17 @@ void register_Fahrenheit_class(){ } Fahrenheit_exposer.def( bp::self * bp::other< double >() ); Fahrenheit_exposer.def( bp::self * bp::other< int >() ); + Fahrenheit_exposer.def( bp::self * bp::other< SireUnits::Dimension::GeneralUnit >() ); Fahrenheit_exposer.def( bp::self + bp::self ); Fahrenheit_exposer.def( bp::self + bp::other< SireUnits::Dimension::PhysUnit< 0, 0, 0, 0, 1, 0, 0 > >() ); + Fahrenheit_exposer.def( bp::self + bp::other< SireUnits::Dimension::GeneralUnit >() ); Fahrenheit_exposer.def( -bp::self ); Fahrenheit_exposer.def( bp::self - bp::self ); Fahrenheit_exposer.def( bp::self - bp::other< SireUnits::Dimension::PhysUnit< 0, 0, 0, 0, 1, 0, 0 > >() ); + Fahrenheit_exposer.def( bp::self - bp::other< SireUnits::Dimension::GeneralUnit >() ); Fahrenheit_exposer.def( bp::self / bp::other< double >() ); Fahrenheit_exposer.def( bp::self / bp::other< int >() ); + Fahrenheit_exposer.def( bp::self / bp::other< SireUnits::Dimension::GeneralUnit >() ); { //::SireUnits::Fahrenheit::operator= typedef ::SireUnits::Fahrenheit & ( ::SireUnits::Fahrenheit::*assign_function_type)( ::SireUnits::Fahrenheit const & ) ; @@ -104,6 +110,10 @@ void register_Fahrenheit_class(){ Fahrenheit_exposer.def( bp::other() - bp::self ); Fahrenheit_exposer.def( bp::other() * bp::self ); Fahrenheit_exposer.def( bp::other() / bp::self ); + Fahrenheit_exposer.def( bp::self + bp::other() ); + Fahrenheit_exposer.def( bp::self - bp::other() ); + Fahrenheit_exposer.def( bp::self * bp::other() ); + Fahrenheit_exposer.def( bp::self / bp::other() ); Fahrenheit_exposer.def( "__copy__", &__copy__); Fahrenheit_exposer.def( "__deepcopy__", &__copy__); Fahrenheit_exposer.def( "clone", &__copy__); diff --git a/wrapper/Units/GeneralUnit.pypp.cpp b/wrapper/Units/GeneralUnit.pypp.cpp index c996cdd75..545017de6 100644 --- a/wrapper/Units/GeneralUnit.pypp.cpp +++ b/wrapper/Units/GeneralUnit.pypp.cpp @@ -29,6 +29,8 @@ namespace bp = boost::python; #include "generalunit.h" +#include "generalunit.h" + SireUnits::Dimension::GeneralUnit __copy__(const SireUnits::Dimension::GeneralUnit &other){ return SireUnits::Dimension::GeneralUnit(other); } #include "Qt/qdatastream.hpp" @@ -45,6 +47,11 @@ void register_GeneralUnit_class(){ bp::scope GeneralUnit_scope( GeneralUnit_exposer ); GeneralUnit_exposer.def( bp::init< SireUnits::Dimension::TempBase const & >(( bp::arg("temperature") ), "") ); GeneralUnit_exposer.def( bp::init< double >(( bp::arg("value") ), "") ); + GeneralUnit_exposer.def( bp::init< SireUnits::Dimension::PhysUnit< -1, -3, 2, 2, 0, 0, 0 > const & >(( bp::arg("unit") ), "") ); + GeneralUnit_exposer.def( bp::init< SireUnits::Dimension::PhysUnit< 1, 2, -2, 0, -1, -1, 0 > const & >(( bp::arg("unit") ), "") ); + GeneralUnit_exposer.def( bp::init< SireUnits::Dimension::PhysUnit< 1, 1, 0, -2, 0, 0, 0 > const & >(( bp::arg("unit") ), "") ); + GeneralUnit_exposer.def( bp::init< SireUnits::Dimension::PhysUnit< -1, 3, -2, 0, 0, 0, 0 > const & >(( bp::arg("unit") ), "") ); + GeneralUnit_exposer.def( bp::init< SireUnits::Dimension::PhysUnit< 1, 2, -1, 0, 0, 0, 0 > const & >(( bp::arg("unit") ), "") ); GeneralUnit_exposer.def( bp::init< SireUnits::Dimension::GeneralUnit const & >(( bp::arg("other") ), "") ); { //::SireUnits::Dimension::GeneralUnit::ANGLE @@ -243,18 +250,20 @@ void register_GeneralUnit_class(){ } GeneralUnit_exposer.def( bp::self != bp::self ); GeneralUnit_exposer.def( bp::self * bp::self ); + GeneralUnit_exposer.def( bp::self * bp::other< SireUnits::Dimension::TempBase >() ); GeneralUnit_exposer.def( bp::self * bp::other< double >() ); GeneralUnit_exposer.def( bp::self * bp::other< int >() ); - GeneralUnit_exposer.def( bp::self *= bp::self ); GeneralUnit_exposer.def( bp::self + bp::self ); + GeneralUnit_exposer.def( bp::self + bp::other< SireUnits::Dimension::TempBase >() ); GeneralUnit_exposer.def( bp::self + bp::other< double >() ); GeneralUnit_exposer.def( -bp::self ); GeneralUnit_exposer.def( bp::self - bp::self ); + GeneralUnit_exposer.def( bp::self - bp::other< SireUnits::Dimension::TempBase >() ); GeneralUnit_exposer.def( bp::self - bp::other< double >() ); GeneralUnit_exposer.def( bp::self / bp::self ); + GeneralUnit_exposer.def( bp::self / bp::other< SireUnits::Dimension::TempBase >() ); GeneralUnit_exposer.def( bp::self / bp::other< double >() ); GeneralUnit_exposer.def( bp::self / bp::other< int >() ); - GeneralUnit_exposer.def( bp::self /= bp::self ); GeneralUnit_exposer.def( bp::self < bp::self ); GeneralUnit_exposer.def( bp::self <= bp::self ); { //::SireUnits::Dimension::GeneralUnit::operator= diff --git a/wrapper/Units/SireUnits_registrars.cpp b/wrapper/Units/SireUnits_registrars.cpp index 5b6447a20..10f00bf6f 100644 --- a/wrapper/Units/SireUnits_registrars.cpp +++ b/wrapper/Units/SireUnits_registrars.cpp @@ -41,6 +41,11 @@ void register_SireUnits_objects() ObjectRegistry::registerConverterFor< SireUnits::Dimension::Capacitance >(); ObjectRegistry::registerConverterFor< SireUnits::Dimension::Current >(); ObjectRegistry::registerConverterFor< SireUnits::Dimension::Potential >(); + ObjectRegistry::registerConverterFor< SireUnits::Dimension::Constant1 >(); + ObjectRegistry::registerConverterFor< SireUnits::Dimension::Constant2 >(); + ObjectRegistry::registerConverterFor< SireUnits::Dimension::Constant3 >(); + ObjectRegistry::registerConverterFor< SireUnits::Dimension::Constant4 >(); + ObjectRegistry::registerConverterFor< SireUnits::Dimension::Constant5 >(); ObjectRegistry::registerConverterFor< SireUnits::Dimension::GeneralUnit >(); } diff --git a/wrapper/Units/TempBase.pypp.cpp b/wrapper/Units/TempBase.pypp.cpp index 771618de8..1b49921d5 100644 --- a/wrapper/Units/TempBase.pypp.cpp +++ b/wrapper/Units/TempBase.pypp.cpp @@ -11,6 +11,8 @@ namespace bp = boost::python; #include "temperature.h" +#include "generalunit.h" + #include "Helpers/str.hpp" #include "Helpers/release_gil_policy.hpp" diff --git a/wrapper/Units/special_code.py b/wrapper/Units/special_code.py index a8bd9cb93..56175fa87 100644 --- a/wrapper/Units/special_code.py +++ b/wrapper/Units/special_code.py @@ -7,13 +7,14 @@ import re + def findGlobals(): - #read in the information about this module + # read in the information about this module lines = open("module_info", "r").readlines() root = lines[2].split()[1] sourcedir = lines[1].split()[1] - lines = open("%s/%s/units.h" % (root,sourcedir), "r").readlines() + lines = open("%s/%s/units.h" % (root, sourcedir), "r").readlines() FILE = open("_Units_global_variables.pyman.hpp", "w") @@ -26,10 +27,10 @@ def findGlobals(): FILE = open("_Units_global_variables.pyman.cpp", "w") - print("\n#include \"_Units_global_variables.pyman.hpp\"", file=FILE) + print('\n#include "_Units_global_variables.pyman.hpp"', file=FILE) print("#include ", file=FILE) - print("#include \"SireUnits/units.h\"", file=FILE) - print("#include \"SireUnits/temperature.h\"", file=FILE) + print('#include "SireUnits/units.h"', file=FILE) + print('#include "SireUnits/temperature.h"', file=FILE) print("\nusing namespace boost::python;", file=FILE) print("using namespace SireUnits;", file=FILE) print("using namespace SireUnits::Dimension;\n", file=FILE) @@ -37,54 +38,84 @@ def findGlobals(): print("void register_man_global_variables()", file=FILE) print("{", file=FILE) - for line in lines: match = re.search(r"const Dimension::([\w\d\-<,>]+)\s+(\w+)", line) if match: name = match.group(2) - print(" scope().attr(\"%s\") = %s;\n" % (name,name), file=FILE) + print(' scope().attr("%s") = %s;\n' % (name, name), file=FILE) else: - match = re.search(r"const double\s+(\w+)", line) + match = re.search(r"const GeneralUnit\s+(\w+)", line) if match: name = match.group(1) - print(" scope().attr(\"%s\") = %s;\n" % (name,name), file=FILE) - + print( + ' scope().attr("%s") = %s;\n' % (name, name), file=FILE + ) - - #add Celsius and Fahrenheit manually - print(" scope().attr(\"celsius\") = celsius;\n", file=FILE) - print(" scope().attr(\"fahrenheit\") = fahrenheit;\n", file=FILE) + # add Celsius and Fahrenheit manually + print(' scope().attr("celsius") = celsius;\n', file=FILE) + print(' scope().attr("fahrenheit") = fahrenheit;\n', file=FILE) print("}\n", file=FILE) + def fix_GeneralUnit(c): c.add_registration_code("def( bp::other() + bp::self )") c.add_registration_code("def( bp::other() - bp::self )") c.add_registration_code("def( bp::other() * bp::self )") c.add_registration_code("def( bp::other() / bp::self )") -def fixMB(mb): - mb.add_declaration_code("#include \"SireUnits/temperature.h\"") - mb.add_declaration_code("#include \"sireunits_dimensions.h\"") - mb.add_declaration_code("#include \"generalunit.h\"") - mb.add_declaration_code("#include \"_Units_global_variables.pyman.hpp\"") + c.add_declaration_code('#include "generalunit.h"') - mb.add_registration_code("register_SireUnits_dimensions();") - mb.add_registration_code("register_man_global_variables();") +def fix_Temperature(c): + c.add_registration_code("def( bp::other() + bp::self )") + c.add_registration_code("def( bp::other() - bp::self )") + c.add_registration_code("def( bp::other() * bp::self )") + c.add_registration_code("def( bp::other() / bp::self )") + + c.add_declaration_code('#include "generalunit.h"') + + c.add_registration_code( + "def( bp::self + bp::other() )" + ) + c.add_registration_code( + "def( bp::self - bp::other() )" + ) + c.add_registration_code( + "def( bp::self * bp::other() )" + ) + c.add_registration_code( + "def( bp::self / bp::other() )" + ) + + +def fix_TempBase(c): + c.add_declaration_code('#include "generalunit.h"') + + +def fixMB(mb): + mb.add_declaration_code('#include "SireUnits/temperature.h"') + mb.add_declaration_code('#include "sireunits_dimensions.h"') + mb.add_declaration_code('#include "generalunit.h"') + mb.add_declaration_code('#include "_Units_global_variables.pyman.hpp"') - #add all of the global physical constants to the module - findGlobals() + mb.add_registration_code("register_SireUnits_dimensions();") + mb.add_registration_code("register_man_global_variables();") + # add all of the global physical constants to the module + findGlobals() -special_code = { "SireUnits::Dimension::GeneralUnit" : fix_GeneralUnit, - "SireUnits::Celsius" : fix_GeneralUnit, - "SireUnits::Fahrenheit" : fix_GeneralUnit } -implicitly_convertible = [ ("SireUnits::Dimension::TempBase", - "SireUnits::Dimension::Temperature"), - ("double", "SireUnits::Dimension::GeneralUnit"), - ] +special_code = { + "SireUnits::Dimension::GeneralUnit": fix_GeneralUnit, + "SireUnits::Celsius": fix_Temperature, + "SireUnits::Fahrenheit": fix_Temperature, + "SireUnits::Dimension::TempBase": fix_TempBase, +} +implicitly_convertible = [ + ("SireUnits::Dimension::TempBase", "SireUnits::Dimension::Temperature"), + ("double", "SireUnits::Dimension::GeneralUnit"), +]