Skip to content

Commit

Permalink
Included Anrey's suggestions. Updated help
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatovmg committed Aug 12, 2020
1 parent 52c1880 commit c9809bd
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 251 deletions.
40 changes: 1 addition & 39 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,16 @@ sandbox/
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

Expand All @@ -56,17 +27,8 @@ out/
# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
fabric.properties
41 changes: 26 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()

if(CMAKE_VERSION VERSION_GREATER 3.9)
cmake_policy(SET CMP0069 NEW)
endif()
cmake_policy(SET CMP0069 NEW)

project(NRGmin VERSION 1.0
DESCRIPTION "Energy minimization utility"
LANGUAGES C)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

option(BUILD_TESTS "Build tests" ON)
option(USE_LTO "Link Time Optimization" ON)
Expand All @@ -24,17 +22,14 @@ option(NOE "Build with NOE feature" ON)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")

if (UNIX)
add_compile_options(-std=c11)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-pg -Wall -Wshadow -Wpointer-arith -Wcast-qual -Winline -Werror -Wextra -Wfatal-errors -Wstrict-prototypes)
endif()
if (UNIX AND CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-pg -Wall -Wshadow -Wpointer-arith -Wcast-qual -Winline -Werror -Wextra -Wfatal-errors -Wstrict-prototypes)
endif()

if (USE_SANITIZER)
set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS}")
add_compile_options(${SANITIZER_FLAGS})
add_link_options(${SANITIZER_FLAGS})
endif()

if (NOE)
Expand All @@ -54,11 +49,27 @@ set(INCLUDE_LIST
"${MOL2_INCLUDE_DIRS}"
"${JANSSON_INCLUDE_DIRS}")

# Read help text from the file and plug it in parse_options.c.in
file(STRINGS ${PROJECT_SOURCE_DIR}/src/usage.txt USAGE_LINES)
# Join lines using "\" character. Can't use string(JOIN ..) here,
# because it exists only in the newer versions of cmake
set(USAGE_TEXT "")
list(LENGTH USAGE_LINES USAGE_N_LINES)
math(EXPR USAGE_LAST_LINE "${USAGE_N_LINES} - 1")
foreach(LINE_ID RANGE ${USAGE_LAST_LINE})
list(GET USAGE_LINES ${LINE_ID} LINE)
set(USAGE_TEXT "${USAGE_TEXT}\\n${LINE}")
endforeach()
configure_file (
"${PROJECT_SOURCE_DIR}/src/parse_options.c.in"
"${PROJECT_BINARY_DIR}/parse_options.c"
)

set(SRC_LIST
${PROJECT_SOURCE_DIR}/src/setup.c
${PROJECT_SOURCE_DIR}/src/parse_options.c
${PROJECT_SOURCE_DIR}/src/utils.c
${PROJECT_SOURCE_DIR}/src/energy.c)
${PROJECT_SOURCE_DIR}/src/energy.c
${PROJECT_BINARY_DIR}/parse_options.c)

add_executable(nrgmin ${PROJECT_SOURCE_DIR}/src/minimize.c ${SRC_LIST})

Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Utility for molecular mechanics energy minimization

## Installation ###

1. Install [libmol2](https://bitbucket.org/bu-structure/libmol2/src/master)
1. Install [libmol2](https://bitbucket.org/bu-structure/libmol2/src/master)
(verified to work with commit
[918978d](https://bitbucket.org/bu-structure/libmol2/src/918978da2c8b3929702df9f7738b1eec60190056/))

2. Build minimization executable

Expand All @@ -13,8 +15,20 @@ Utility for molecular mechanics energy minimization
3. The binary is in `build/nrgmin`

4. If you want to build with OpenMP, add `-DOPENMP=ON` to `cmake` command, it will create additional executable
4. To build OpenMP enabled binary, add `-DOPENMP=YES` to `cmake` command, it will create additional executable
`build/nrgmin.omp`. `--num-threads` controls the number of OpenMP threads.

CMake flags:

* `BUILD_TESTS` — set to `YES` to enable tests, and to `NO` if you don't need them.

* `USE_LTO` – set to `YES` for Link Time Optimization.

* `USE_SANITIZER` — enable AddressSanitizer. Not recommended for release builds, since it complicates linking to other projects.

* `OPENMP` — set to `YES` to create a multithreaded binary `nrgmin.omp` in addition to a serial one.

* `NOE` — set to `NO` if you want to drop NOE (NMR) calculation capability (e.g. if libmol2 was build without NOE).

## How to run

Expand Down Expand Up @@ -198,6 +212,8 @@ Energy terms switches. Everything is on by default except for GBSA
--impropers-on/--impropers-on Impropers
--vdw-on/--vdw-off VDW
--vdw03-on/--vdw03-off 1-4 VDW
--eleng-on/--eleng-off Coulomb electrostatics
--elengs03-on/--elengs03-off 1-4 Coulomb electrostatics
--gbsa-on/gbsa-off GBSA

Fixed atoms (in rec/lig mode ligand atom IDs must be increased by the number of receptor atoms)
Expand Down
98 changes: 40 additions & 58 deletions src/energy.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,39 +180,31 @@ lbfgsfloatval_t energy_func(


void pointspring_energy(const struct pointsprings_setup *sprst, struct mol_atom_group *ag, double *een) {
size_t i, i1, i2, nat;
double xtot, ytot, ztot, fk;
struct mol_vector3 g;

for (i = 0; i < sprst->nsprings; i++) {
nat = sprst->springs[i].natoms;
for (size_t i = 0; i < sprst->nsprings; i++) {
size_t nat = sprst->springs[i].natoms;

if (nat > 0) {
xtot = 0.0;
ytot = 0.0;
ztot = 0.0;

for (i1 = 0; i1 < nat; i1++) {
i2 = sprst->springs[i].atoms[i1];
xtot += ag->coords[i2].X;
ytot += ag->coords[i2].Y;
ztot += ag->coords[i2].Z;
struct mol_vector3 tot_vec = {0, 0, 0};
struct mol_vector3 g;

for (size_t i1 = 0; i1 < nat; i1++) {
size_t i2 = sprst->springs[i].atoms[i1];
MOL_VEC_ADD(tot_vec, tot_vec, ag->coords[i2]);
}

xtot = xtot / nat - sprst->springs[i].X0;
ytot = ytot / nat - sprst->springs[i].Y0;
ztot = ztot / nat - sprst->springs[i].Z0;
MOL_VEC_DIV_SCALAR(tot_vec, tot_vec, nat);
tot_vec.X -= sprst->springs[i].X0;
tot_vec.Y -= sprst->springs[i].Y0;
tot_vec.Z -= sprst->springs[i].Z0;

fk = sprst->springs[i].weight;
(*een) += fk * (xtot * xtot + ytot * ytot + ztot * ztot);
double fk = sprst->springs[i].weight;
(*een) += fk * MOL_VEC_SQ_NORM(tot_vec);

fk = 2 * fk / nat;
g.X = xtot * fk;
g.Y = ytot * fk;
g.Z = ztot * fk;
MOL_VEC_MULT_SCALAR(g, tot_vec, fk);

for (i1 = 0; i1 < nat; i1++) {
i2 = sprst->springs[i].atoms[i1];
for (size_t i1 = 0; i1 < nat; i1++) {
size_t i2 = sprst->springs[i].atoms[i1];
MOL_VEC_SUB(ag->gradients[i2], ag->gradients[i2], g);
}
}
Expand All @@ -221,38 +213,28 @@ void pointspring_energy(const struct pointsprings_setup *sprst, struct mol_atom_


void pairspring_energy(const struct pairsprings_setup *sprst, struct mol_atom_group *ag, double *een) {
size_t i, i1, i2;
double xtot, ytot, ztot, fk, d, d2, ln, er, coef, delta;
struct mol_vector3 g;

for (i = 0; i < sprst->nsprings; i++) {
ln = sprst->springs[i].length;
er = sprst->springs[i].error;
fk = sprst->springs[i].weight / 2.0;

i1 = sprst->springs[i].atoms[0];
i2 = sprst->springs[i].atoms[1];

xtot = ag->coords[i2].X - ag->coords[i1].X;
ytot = ag->coords[i2].Y - ag->coords[i1].Y;
ztot = ag->coords[i2].Z - ag->coords[i1].Z;

d2 = xtot * xtot + ytot * ytot + ztot * ztot;
d = sqrt(d2);

delta = fabs(d - ln);
delta = (delta > er) ? ((delta - er) * delta / (d - ln)) : 0.0;

//(*een) += fk * (d - ln) * (d - ln);
(*een) += fk * delta * delta;
//coef = fk * 2 * (1.0 - ln / d);
coef = fk * 2.0 * delta / d;

g.X = -coef * xtot;
g.Y = -coef * ytot;
g.Z = -coef * ztot;

MOL_VEC_SUB(ag->gradients[i1], ag->gradients[i1], g);
MOL_VEC_ADD(ag->gradients[i2], ag->gradients[i2], g);
for (size_t i = 0; i < sprst->nsprings; i++) {
struct mol_vector3 g;
double ln = sprst->springs[i].length;
double er = sprst->springs[i].error;
double fk = sprst->springs[i].weight / 2.0; //TODO: remove the two here after we are done with NOE testing

size_t i1 = sprst->springs[i].atoms[0];
size_t i2 = sprst->springs[i].atoms[1];

struct mol_vector3 tot_vec;
MOL_VEC_SUB(tot_vec, ag->coords[i2], ag->coords[i1]);
double d = sqrt(MOL_VEC_SQ_NORM(tot_vec));

double delta = fabs(d - ln);
if (delta > er) {
delta = (delta - er) * delta / (d - ln);
(*een) += fk * delta * delta;
double coef = fk * 2.0 * delta / d;
MOL_VEC_MULT_SCALAR(g, tot_vec, -coef);

MOL_VEC_SUB(ag->gradients[i1], ag->gradients[i1], g);
MOL_VEC_ADD(ag->gradients[i2], ag->gradients[i2], g);
}
}
}
1 change: 0 additions & 1 deletion src/minimize.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ int main(int argc, char **argv) {
if (opts_error) {
ERR_MSG("Couldn't parse options");
options_free(opts);
usage_message(argv);
exit(EXIT_FAILURE);
}
if (opts.help) {
Expand Down
Loading

0 comments on commit c9809bd

Please sign in to comment.