Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature optimise lever #134

Merged
merged 9 commits into from
Dec 8, 2023
87 changes: 53 additions & 34 deletions corelib/src/libs/SireIO/moleculeparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1929,8 +1929,19 @@ MoleculeParserPtr MoleculeParser::parse(const System &system, const QString &for
cannot be recognised, or if there is an error in parsing. */
MoleculeParserPtr MoleculeParser::parse(const QString &filename, const PropertyMap &map)
{
MoleculeParserPtr parser = MoleculeParser::_pvt_parse(filename, map);
getFileCache()->clear();
MoleculeParserPtr parser;

try
{
parser = MoleculeParser::_pvt_parse(filename, map);
getFileCache()->clear();
}
catch (...)
{
getFileCache()->clear();
throw;
}

return parser;
}

Expand All @@ -1939,48 +1950,56 @@ QList<MoleculeParserPtr> MoleculeParser::parse(const QStringList &filenames, con
{
QList<MoleculeParserPtr> result;

if (filenames.count() == 1)
{
result.append(MoleculeParser::_pvt_parse(filenames[0], map));
}
else
try
{
QVector<MoleculeParserPtr> parsers(filenames.count());

bool run_parallel = true;

if (map["parallel"].hasValue())
if (filenames.count() == 1)
{
run_parallel = map["parallel"].value().asA<BooleanProperty>().value();
}

if (run_parallel)
{
// parse the files in parallel - we use a grain size of 1
// as each file can be pretty big, and there won't be many of them
tbb::parallel_for(
tbb::blocked_range<int>(0, filenames.count(), 1),
[&](tbb::blocked_range<int> r)
{
for (int i = r.begin(); i < r.end(); ++i)
{
parsers[i] = MoleculeParser::_pvt_parse(filenames[i], map);
}
},
tbb::simple_partitioner());
result.append(MoleculeParser::_pvt_parse(filenames[0], map));
}
else
{
for (int i = 0; i < filenames.count(); ++i)
QVector<MoleculeParserPtr> parsers(filenames.count());

bool run_parallel = true;

if (map["parallel"].hasValue())
{
run_parallel = map["parallel"].value().asA<BooleanProperty>().value();
}

if (run_parallel)
{
parsers[i] = MoleculeParser::_pvt_parse(filenames[i], map);
// parse the files in parallel - we use a grain size of 1
// as each file can be pretty big, and there won't be many of them
tbb::parallel_for(
tbb::blocked_range<int>(0, filenames.count(), 1),
[&](tbb::blocked_range<int> r)
{
for (int i = r.begin(); i < r.end(); ++i)
{
parsers[i] = MoleculeParser::_pvt_parse(filenames[i], map);
}
},
tbb::simple_partitioner());
}
else
{
for (int i = 0; i < filenames.count(); ++i)
{
parsers[i] = MoleculeParser::_pvt_parse(filenames[i], map);
}
}

result = parsers.toList();
}

result = parsers.toList();
getFileCache()->clear();
}
catch (...)
{
getFileCache()->clear();
throw;
}

getFileCache()->clear();

return result;
}
Expand Down
9 changes: 9 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ organisation on `GitHub <https://github.com/openbiosim/sire>`__.
a zero sigma value. They will either be sigma=1/epsilon=0 for non-perturbable
atoms, or sigma=1e-9/epsilon=1e-9 for perturbable atoms.

* Optimised the ``LambaLever`` class so that it caches the forcefield parameters
calculated at different lambda values. This means that we don't have to
re-calculate the parameters at each lambda update step. This is a
significant speed-up for alchemical free energy simulations.

* Now catch ``std::bad_alloc`` and raise it as a ``MemoryError``. This
means that we can catch out-of-memory errors and raise a more
informative exception.

* Please add an item to this changelog when you create your PR

`2023.4.1 <https://github.com/openbiosim/sire/compare/2023.4.0...2023.4.1>`__ - October 2023
Expand Down
19 changes: 19 additions & 0 deletions wrapper/Convert/SireOpenMM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ if (${SIRE_USE_OPENMM})
# Other python wrapping directories
include_directories(${CMAKE_SOURCE_DIR})

# Check to see if we have support for updating some parameters in context
include(CheckCXXSourceCompiles)
check_cxx_source_compiles( "#include <openmm/CustomNonbondedForce.h>
int main() {
OpenMM::CustomNonbondedForce *force;
OpenMM::Context *context;
force->updateSomeParametersInContext(0, 0, *context);
return 0;
}"
SIREOPENMM_HAS_UPDATESOMEPARAMETERSINCONTEXT )

if ( ${SIREOPENMM_HAS_UPDATESOMEPARAMETERSINCONTEXT} )
message( STATUS "OpenMM has support for updating some parameters in context")
add_definitions("-DSIRE_HAS_UPDATE_SOME_IN_CONTEXT")
else()
message( STATUS "OpenMM does not have support for updating some parameters in context")
message( STATUS "The free energy code will be a little slower.")
endif()

# Define the sources in SireOpenMM
set ( SIREOPENMM_SOURCES

Expand Down
Loading