Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
f2276667
Commit
f2276667
authored
May 23, 2013
by
Yutong Zhao
Browse files
Merge branch 'master' of
https://github.com/SimTk/openmm
parents
ec39f6ff
7521da4a
Changes
30
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
845 additions
and
86 deletions
+845
-86
plugins/drude/serialization/include/openmm/serialization/DrudeLangevinIntegratorProxy.h
...clude/openmm/serialization/DrudeLangevinIntegratorProxy.h
+53
-0
plugins/drude/serialization/include/openmm/serialization/internal/windowsExportDrudeSerialization.h
.../serialization/internal/windowsExportDrudeSerialization.h
+41
-0
plugins/drude/serialization/src/DrudeForceProxy.cpp
plugins/drude/serialization/src/DrudeForceProxy.cpp
+86
-0
plugins/drude/serialization/src/DrudeLangevinIntegratorProxy.cpp
.../drude/serialization/src/DrudeLangevinIntegratorProxy.cpp
+64
-0
plugins/drude/serialization/src/DrudeSerializationProxyRegistration.cpp
...serialization/src/DrudeSerializationProxyRegistration.cpp
+69
-0
plugins/drude/serialization/tests/CMakeLists.txt
plugins/drude/serialization/tests/CMakeLists.txt
+17
-0
plugins/drude/serialization/tests/TestSerializeDrudeForce.cpp
...ins/drude/serialization/tests/TestSerializeDrudeForce.cpp
+104
-0
plugins/drude/serialization/tests/TestSerializeDrudeLangevinIntegrator.cpp
...ialization/tests/TestSerializeDrudeLangevinIntegrator.cpp
+78
-0
wrappers/python/simtk/openmm/app/forcefield.py
wrappers/python/simtk/openmm/app/forcefield.py
+171
-82
wrappers/python/simtk/openmm/app/modeller.py
wrappers/python/simtk/openmm/app/modeller.py
+162
-4
No files found.
plugins/drude/serialization/include/openmm/serialization/DrudeLangevinIntegratorProxy.h
0 → 100644
View file @
f2276667
#ifndef OPENMM_DRUDE_LANGEVIN_INTEGRATOR_PROXY_H_
#define OPENMM_DRUDE_LANGEVIN_INTEGRATOR_PROXY_H_
/* -------------------------------------------------------------------------- *
* OpenMMDrude *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2013 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/internal/windowsExportDrudeSerialization.h"
#include "openmm/serialization/SerializationProxy.h"
namespace
OpenMM
{
/**
* This is a proxy for serializing DrudeLangevinIntegrator objects.
*/
class
OPENMM_EXPORT_DRUDE_SERIALIZATION
DrudeLangevinIntegratorProxy
:
public
SerializationProxy
{
public:
DrudeLangevinIntegratorProxy
();
void
serialize
(
const
void
*
object
,
SerializationNode
&
node
)
const
;
void
*
deserialize
(
const
SerializationNode
&
node
)
const
;
};
}
// namespace OpenMM
#endif
/*OPENMM_DRUDE_LANGEVIN_INTEGRATOR_PROXY_H_*/
plugins/drude/serialization/include/openmm/serialization/internal/windowsExportDrudeSerialization.h
0 → 100644
View file @
f2276667
#ifndef OPENMM_WINDOWSEXPORTDRUDESERIALIZATION_H_
#define OPENMM_WINDOWSEXPORTDRUDESERIALIZATION_H_
/*
* Shared libraries are messy in Visual Studio. We have to distinguish three
* cases:
* (1) this header is being used to build the OpenMM shared library
* (dllexport)
* (2) this header is being used by a *client* of the OpenMM shared
* library (dllimport)
* (3) we are building the OpenMM static library, or the client is
* being compiled with the expectation of linking with the
* OpenMM static library (nothing special needed)
* In the CMake script for building this library, we define one of the symbols
* OPENMM_DRUDE_SERIALIZATION_BUILDING_{SHARED|STATIC}_LIBRARY
* Client code normally has no special symbol defined, in which case we'll
* assume it wants to use the shared library. However, if the client defines
* the symbol OPENMM_USE_STATIC_LIBRARIES we'll suppress the dllimport so
* that the client code can be linked with static libraries. Note that
* the client symbol is not library dependent, while the library symbols
* affect only the OpenMM library, meaning that other libraries can
* be clients of this one. However, we are assuming all-static or all-shared.
*/
#ifdef _MSC_VER
// We don't want to hear about how sprintf is "unsafe".
#pragma warning(disable:4996)
// Keep MS VC++ quiet about lack of dll export of private members.
#pragma warning(disable:4251)
#if defined(OPENMM_DRUDE_SERIALIZATION_BUILDING_SHARED_LIBRARY)
#define OPENMM_EXPORT_DRUDE_SERIALIZATION __declspec(dllexport)
#elif defined(OPENMM_DRUDE_SERIALIZATION_BUILDING_STATIC_LIBRARY) || defined(OPENMM_DRUDE_SERIALIZATION_USE_STATIC_LIBRARIES)
#define OPENMM_EXPORT_DRUDE_SERIALIZATION
#else
#define OPENMM_EXPORT_DRUDE_SERIALIZATION __declspec(dllimport) // i.e., a client of a shared library
#endif
#else
#define OPENMM_EXPORT_DRUDE_SERIALIZATION // Linux, Mac
#endif
#endif // OPENMM_WINDOWSEXPORTDRUDESERIALIZATION_H_
plugins/drude/serialization/src/DrudeForceProxy.cpp
0 → 100644
View file @
f2276667
/* -------------------------------------------------------------------------- *
* OpenMMDrude *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2013 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/DrudeForceProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/Force.h"
#include "openmm/DrudeForce.h"
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
DrudeForceProxy
::
DrudeForceProxy
()
:
SerializationProxy
(
"DrudeForce"
)
{
}
void
DrudeForceProxy
::
serialize
(
const
void
*
object
,
SerializationNode
&
node
)
const
{
node
.
setIntProperty
(
"version"
,
1
);
const
DrudeForce
&
force
=
*
reinterpret_cast
<
const
DrudeForce
*>
(
object
);
SerializationNode
&
particles
=
node
.
createChildNode
(
"Particles"
);
for
(
int
i
=
0
;
i
<
force
.
getNumParticles
();
i
++
)
{
int
p
,
p1
,
p2
,
p3
,
p4
;
double
charge
,
polarizability
,
aniso12
,
aniso34
;
force
.
getParticleParameters
(
i
,
p
,
p1
,
p2
,
p3
,
p4
,
charge
,
polarizability
,
aniso12
,
aniso34
);
particles
.
createChildNode
(
"Particle"
).
setIntProperty
(
"p"
,
p
).
setIntProperty
(
"p1"
,
p1
).
setIntProperty
(
"p2"
,
p2
).
setIntProperty
(
"p3"
,
p3
).
setIntProperty
(
"p4"
,
p4
)
.
setDoubleProperty
(
"charge"
,
charge
).
setDoubleProperty
(
"polarizability"
,
polarizability
).
setDoubleProperty
(
"a12"
,
aniso12
).
setDoubleProperty
(
"a34"
,
aniso34
);
}
SerializationNode
&
pairs
=
node
.
createChildNode
(
"ScreenedPairs"
);
for
(
int
i
=
0
;
i
<
force
.
getNumScreenedPairs
();
i
++
)
{
int
p1
,
p2
;
double
thole
;
force
.
getScreenedPairParameters
(
i
,
p1
,
p2
,
thole
);
pairs
.
createChildNode
(
"Pair"
).
setIntProperty
(
"p1"
,
p1
).
setIntProperty
(
"p2"
,
p2
).
setDoubleProperty
(
"thole"
,
thole
);
}
}
void
*
DrudeForceProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
if
(
node
.
getIntProperty
(
"version"
)
!=
1
)
throw
OpenMMException
(
"Unsupported version number"
);
DrudeForce
*
force
=
new
DrudeForce
();
try
{
const
SerializationNode
&
particles
=
node
.
getChildNode
(
"Particles"
);
for
(
int
i
=
0
;
i
<
(
int
)
particles
.
getChildren
().
size
();
i
++
)
{
const
SerializationNode
&
particle
=
particles
.
getChildren
()[
i
];
force
->
addParticle
(
particle
.
getIntProperty
(
"p"
),
particle
.
getIntProperty
(
"p1"
),
particle
.
getIntProperty
(
"p2"
),
particle
.
getIntProperty
(
"p3"
),
particle
.
getIntProperty
(
"p4"
),
particle
.
getDoubleProperty
(
"charge"
),
particle
.
getDoubleProperty
(
"polarizability"
),
particle
.
getDoubleProperty
(
"a12"
),
particle
.
getDoubleProperty
(
"a34"
));
}
const
SerializationNode
&
pairs
=
node
.
getChildNode
(
"ScreenedPairs"
);
for
(
int
i
=
0
;
i
<
(
int
)
pairs
.
getChildren
().
size
();
i
++
)
{
const
SerializationNode
&
pair
=
pairs
.
getChildren
()[
i
];
force
->
addScreenedPair
(
pair
.
getIntProperty
(
"p1"
),
pair
.
getIntProperty
(
"p2"
),
pair
.
getDoubleProperty
(
"thole"
));
}
}
catch
(...)
{
delete
force
;
throw
;
}
return
force
;
}
plugins/drude/serialization/src/DrudeLangevinIntegratorProxy.cpp
0 → 100644
View file @
f2276667
/* -------------------------------------------------------------------------- *
* OpenMMDrude *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2013 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/DrudeLangevinIntegratorProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/DrudeLangevinIntegrator.h"
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
DrudeLangevinIntegratorProxy
::
DrudeLangevinIntegratorProxy
()
:
SerializationProxy
(
"DrudeLangevinIntegrator"
)
{
}
void
DrudeLangevinIntegratorProxy
::
serialize
(
const
void
*
object
,
SerializationNode
&
node
)
const
{
node
.
setIntProperty
(
"version"
,
1
);
const
DrudeLangevinIntegrator
&
integrator
=
*
reinterpret_cast
<
const
DrudeLangevinIntegrator
*>
(
object
);
node
.
setDoubleProperty
(
"stepSize"
,
integrator
.
getStepSize
());
node
.
setDoubleProperty
(
"constraintTolerance"
,
integrator
.
getConstraintTolerance
());
node
.
setDoubleProperty
(
"temperature"
,
integrator
.
getTemperature
());
node
.
setDoubleProperty
(
"friction"
,
integrator
.
getFriction
());
node
.
setDoubleProperty
(
"drudeTemperature"
,
integrator
.
getDrudeTemperature
());
node
.
setDoubleProperty
(
"drudeFriction"
,
integrator
.
getDrudeFriction
());
node
.
setIntProperty
(
"randomSeed"
,
integrator
.
getRandomNumberSeed
());
}
void
*
DrudeLangevinIntegratorProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
if
(
node
.
getIntProperty
(
"version"
)
!=
1
)
throw
OpenMMException
(
"Unsupported version number"
);
DrudeLangevinIntegrator
*
integrator
=
new
DrudeLangevinIntegrator
(
node
.
getDoubleProperty
(
"temperature"
),
node
.
getDoubleProperty
(
"friction"
),
node
.
getDoubleProperty
(
"drudeTemperature"
),
node
.
getDoubleProperty
(
"drudeFriction"
),
node
.
getDoubleProperty
(
"stepSize"
));
integrator
->
setConstraintTolerance
(
node
.
getDoubleProperty
(
"constraintTolerance"
));
integrator
->
setRandomNumberSeed
(
node
.
getIntProperty
(
"randomSeed"
));
return
integrator
;
}
\ No newline at end of file
plugins/drude/serialization/src/DrudeSerializationProxyRegistration.cpp
0 → 100644
View file @
f2276667
/* -------------------------------------------------------------------------- *
* OpenMMDrude *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2013 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#ifdef WIN32
#include <windows.h>
#include <sstream>
#else
#include <dlfcn.h>
#include <dirent.h>
#include <cstdlib>
#endif
#include "openmm/OpenMMException.h"
#include "openmm/DrudeForce.h"
#include "openmm/DrudeLangevinIntegrator.h"
#include "openmm/serialization/SerializationProxy.h"
#include "openmm/serialization/DrudeForceProxy.h"
#include "openmm/serialization/DrudeLangevinIntegratorProxy.h"
#include "openmm/serialization/internal/windowsExportDrudeSerialization.h"
#if defined(WIN32)
#include <windows.h>
extern
"C"
OPENMM_EXPORT_DRUDE_SERIALIZATION
void
registerDrudeSerializationProxies
();
BOOL
WINAPI
DllMain
(
HANDLE
hModule
,
DWORD
ul_reason_for_call
,
LPVOID
lpReserved
)
{
if
(
ul_reason_for_call
==
DLL_PROCESS_ATTACH
)
registerDrudeSerializationProxies
();
return
TRUE
;
}
#else
extern
"C"
void
__attribute__
((
constructor
))
registerDrudeSerializationProxies
();
#endif
using
namespace
OpenMM
;
extern
"C"
OPENMM_EXPORT_DRUDE_SERIALIZATION
void
registerDrudeSerializationProxies
()
{
SerializationProxy
::
registerProxy
(
typeid
(
DrudeForce
),
new
DrudeForceProxy
());
SerializationProxy
::
registerProxy
(
typeid
(
DrudeLangevinIntegrator
),
new
DrudeLangevinIntegratorProxy
());
}
plugins/drude/serialization/tests/CMakeLists.txt
0 → 100644
View file @
f2276667
#
# Testing
#
ENABLE_TESTING
()
# Automatically create tests using files named "Test*.cpp"
FILE
(
GLOB TEST_PROGS
"*Test*.cpp"
)
FOREACH
(
TEST_PROG
${
TEST_PROGS
}
)
GET_FILENAME_COMPONENT
(
TEST_ROOT
${
TEST_PROG
}
NAME_WE
)
# All tests use shared libraries
ADD_EXECUTABLE
(
${
TEST_ROOT
}
${
TEST_PROG
}
)
TARGET_LINK_LIBRARIES
(
${
TEST_ROOT
}
${
OPENMM_SERIALIZATION_LIBRARY_NAME
}
${
OPENMM_DRUDE_SERIALIZATION_LIBRARY_NAME
}
${
OPENMM_DRUDE_LIBRARY_NAME
}
)
ADD_TEST
(
${
TEST_ROOT
}
${
EXECUTABLE_OUTPUT_PATH
}
/
${
TEST_ROOT
}
)
ENDFOREACH
(
TEST_PROG
${
TEST_PROGS
}
)
plugins/drude/serialization/tests/TestSerializeDrudeForce.cpp
0 → 100644
View file @
f2276667
/* -------------------------------------------------------------------------- *
* OpenMMDrude *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2013 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/Platform.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/DrudeForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
extern
"C"
void
registerDrudeSerializationProxies
();
void
testSerialization
()
{
// Create a Force.
DrudeForce
force1
;
force1
.
addParticle
(
0
,
1
,
2
,
3
,
4
,
0.5
,
1.0
,
1.5
,
2.0
);
force1
.
addParticle
(
2
,
3
,
7
,
8
,
9
,
0.1
,
1e-4
,
1.0
,
0.9
);
force1
.
addParticle
(
5
,
6
,
-
1
,
-
1
,
-
1
,
0.2
,
0.1
,
1.0
,
1.0
);
force1
.
addScreenedPair
(
0
,
1
,
2.6
);
force1
.
addScreenedPair
(
1
,
2
,
2.2
);
// Serialize and then deserialize it.
stringstream
buffer
;
XmlSerializer
::
serialize
<
DrudeForce
>
(
&
force1
,
"Force"
,
buffer
);
DrudeForce
*
copy
=
XmlSerializer
::
deserialize
<
DrudeForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
DrudeForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force1
.
getNumParticles
(),
force2
.
getNumParticles
());
for
(
int
i
=
0
;
i
<
(
int
)
force1
.
getNumParticles
();
i
++
)
{
int
a1
,
a2
,
a3
,
a4
,
a5
,
b1
,
b2
,
b3
,
b4
,
b5
;
double
charge1
,
charge2
;
double
polar1
,
polar2
;
double
aa12
,
ba12
,
aa34
,
ba34
;
force1
.
getParticleParameters
(
i
,
a1
,
a2
,
a3
,
a4
,
a5
,
charge1
,
polar1
,
aa12
,
aa34
);
force2
.
getParticleParameters
(
i
,
b1
,
b2
,
b3
,
b4
,
b5
,
charge2
,
polar2
,
ba12
,
ba34
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
a3
,
b3
);
ASSERT_EQUAL
(
a4
,
b4
);
ASSERT_EQUAL
(
a5
,
b5
);
ASSERT_EQUAL
(
charge1
,
charge2
);
ASSERT_EQUAL
(
polar1
,
polar2
);
ASSERT_EQUAL
(
aa12
,
ba12
);
ASSERT_EQUAL
(
aa34
,
ba34
);
}
ASSERT_EQUAL
(
force1
.
getNumScreenedPairs
(),
force2
.
getNumScreenedPairs
());
for
(
int
i
=
0
;
i
<
(
int
)
force1
.
getNumScreenedPairs
();
i
++
)
{
int
a1
,
a2
,
b1
,
b2
;
double
thole1
,
thole2
;
force1
.
getScreenedPairParameters
(
i
,
a1
,
a2
,
thole1
);
force1
.
getScreenedPairParameters
(
i
,
b1
,
b2
,
thole2
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
thole1
,
thole2
);
}
}
int
main
()
{
try
{
registerDrudeSerializationProxies
();
testSerialization
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
return
1
;
}
cout
<<
"Done"
<<
endl
;
return
0
;
}
plugins/drude/serialization/tests/TestSerializeDrudeLangevinIntegrator.cpp
0 → 100644
View file @
f2276667
/* -------------------------------------------------------------------------- *
* OpenMMDrude *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2013 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/Platform.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/DrudeLangevinIntegrator.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
extern
"C"
void
registerDrudeSerializationProxies
();
void
testSerialization
()
{
// Create an Integrator.
DrudeLangevinIntegrator
integ1
(
301.1
,
0.95
,
10.5
,
1.2
,
0.001
);
integ1
.
setRandomNumberSeed
(
18
);
// Serialize and then deserialize it.
stringstream
buffer
;
XmlSerializer
::
serialize
<
DrudeLangevinIntegrator
>
(
&
integ1
,
"Integrator"
,
buffer
);
DrudeLangevinIntegrator
*
copy
=
XmlSerializer
::
deserialize
<
DrudeLangevinIntegrator
>
(
buffer
);
// Compare the two integrators to see if they are identical.
DrudeLangevinIntegrator
&
integ2
=
*
copy
;
ASSERT_EQUAL
(
integ1
.
getTemperature
(),
integ2
.
getTemperature
());
ASSERT_EQUAL
(
integ1
.
getFriction
(),
integ2
.
getFriction
());
ASSERT_EQUAL
(
integ1
.
getDrudeTemperature
(),
integ2
.
getDrudeTemperature
());
ASSERT_EQUAL
(
integ1
.
getDrudeFriction
(),
integ2
.
getDrudeFriction
());
ASSERT_EQUAL
(
integ1
.
getRandomNumberSeed
(),
integ2
.
getRandomNumberSeed
());
}
int
main
()
{
try
{
registerDrudeSerializationProxies
();
testSerialization
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
return
1
;
}
cout
<<
"Done"
<<
endl
;
return
0
;
}
wrappers/python/simtk/openmm/app/forcefield.py
View file @
f2276667
This diff is collapsed.
Click to expand it.
wrappers/python/simtk/openmm/app/modeller.py
View file @
f2276667
...
...
@@ -33,11 +33,12 @@ from __future__ import division
__author__
=
"Peter Eastman"
__version__
=
"1.0"
from
simtk.openmm.app
import
Topology
,
PDBFile
from
simtk.openmm.app.forcefield
import
HAngles
from
simtk.openmm.app
import
Topology
,
PDBFile
,
ForceField
from
simtk.openmm.app.forcefield
import
HAngles
,
_createResidueSignature
,
_matchResidue
,
DrudeGenerator
from
simtk.openmm.app.topology
import
Residue
from
simtk.openmm.vec3
import
Vec3
from
simtk.openmm
import
System
,
Context
,
NonbondedForce
,
VerletIntegrator
,
LocalEnergyMinimizer
from
simtk.unit
import
nanometer
,
molar
,
elementary_charge
,
amu
,
gram
,
liter
,
degree
,
sqrt
,
acos
,
is_quantity
,
dot
,
norm
from
simtk.unit
import
nanometer
,
molar
,
elementary_charge
,
amu
,
gram
,
liter
,
degree
,
sqrt
,
acos
,
is_quantity
,
dot
,
norm
,
sum
import
element
as
elem
import
os
import
random
...
...
@@ -516,7 +517,7 @@ class Modeller(object):
terminal
=
hydrogen
.
attrib
[
'terminal'
]
data
.
hydrogens
.
append
(
Modeller
.
_Hydrogen
(
hydrogen
.
attrib
[
'name'
],
hydrogen
.
attrib
[
'parent'
],
maxph
,
atomVariants
,
terminal
))
def
addHydrogens
(
self
,
forcefield
,
pH
=
7.0
,
variants
=
None
,
hydrogenDefinitions
=
None
):
def
addHydrogens
(
self
,
forcefield
,
pH
=
7.0
,
variants
=
None
):
"""Add missing hydrogens to the model.
Some residues can exist in multiple forms depending on the pH and properties of the local environment. These
...
...
@@ -763,3 +764,160 @@ class Modeller(object):
self
.
topology
=
newTopology
self
.
positions
=
context
.
getState
(
getPositions
=
True
).
getPositions
()
return
actualVariants
def
addExtraParticles
(
self
,
forcefield
):
"""Add missing extra particles to the model that are required by a force field.
Some force fields use "extra particles" that do not represent actual atoms, but still need to be included in
the System. Examples include lone pairs, Drude particles, and the virtual sites used in some water models
to adjust the charge distribution. Extra particles can be recognized by the fact that their element is None.
This method is primarily used to add extra particles, but it can also remove them. It tries to match every
residue in the Topology to a template in the force field. If there is no match, it will both add and remove
extra particles as necessary to make it match.
Parameters:
- forcefield (ForceField) the ForceField defining what extra particles should be present
"""
# Create copies of all residue templates that have had all extra points removed.
templatesNoEP
=
{}
for
resName
,
template
in
forcefield
.
_templates
.
iteritems
():
if
any
(
atom
.
element
is
None
for
atom
in
template
.
atoms
):
index
=
0
newIndex
=
{}
newTemplate
=
ForceField
.
_TemplateData
(
resName
)
for
i
,
atom
in
enumerate
(
template
.
atoms
):
if
atom
.
element
is
not
None
:
newIndex
[
i
]
=
index
index
+=
1
newTemplate
.
atoms
.
append
(
ForceField
.
_TemplateAtomData
(
atom
.
name
,
atom
.
type
,
atom
.
element
))
for
b1
,
b2
in
template
.
bonds
:
if
b1
in
newIndex
and
b2
in
newIndex
:
newTemplate
.
bonds
.
append
((
newIndex
[
b1
],
newIndex
[
b2
]))
newTemplate
.
atoms
[
newIndex
[
b1
]].
bondedTo
.
append
(
newIndex
[
b2
])
newTemplate
.
atoms
[
newIndex
[
b2
]].
bondedTo
.
append
(
newIndex
[
b1
])
for
b
in
template
.
externalBonds
:
if
b
in
newIndex
:
newTemplate
.
externalBonds
.
append
(
newIndex
[
b
])
templatesNoEP
[
template
]
=
newTemplate
# Record which atoms are bonded to each other atom, with and without extra particles.
bondedToAtom
=
[]
bondedToAtomNoEP
=
[]
for
atom
in
self
.
topology
.
atoms
():
bondedToAtom
.
append
(
set
())
if
atom
.
element
is
not
None
:
bondedToAtomNoEP
.
append
(
set
())
for
atom1
,
atom2
in
self
.
topology
.
bonds
():
bondedToAtom
[
atom1
.
index
].
add
(
atom2
.
index
)
bondedToAtom
[
atom2
.
index
].
add
(
atom1
.
index
)
if
atom1
.
element
is
not
None
and
atom2
.
element
is
not
None
:
bondedToAtomNoEP
[
atom1
.
index
].
add
(
atom2
.
index
)
bondedToAtomNoEP
[
atom2
.
index
].
add
(
atom1
.
index
)
# If the force field has a DrudeForce, record the types of Drude particles and their parents since we'll
# need them for picking particle positions.
drudeTypeMap
=
{}
for
force
in
forcefield
.
_forces
:
if
isinstance
(
force
,
DrudeGenerator
):
for
type
in
force
.
typeMap
:
drudeTypeMap
[
type
]
=
force
.
typeMap
[
type
][
0
]
# Create the new Topology.
newTopology
=
Topology
()
newTopology
.
setUnitCellDimensions
(
deepcopy
(
self
.
topology
.
getUnitCellDimensions
()))
newAtoms
=
{}
newPositions
=
[]
*
nanometer
for
chain
in
self
.
topology
.
chains
():
newChain
=
newTopology
.
addChain
()
for
residue
in
chain
.
residues
():
newResidue
=
newTopology
.
addResidue
(
residue
.
name
,
newChain
)
# Look for a matching template.
matchFound
=
False
signature
=
_createResidueSignature
([
atom
.
element
for
atom
in
residue
.
atoms
()])
if
signature
in
forcefield
.
_templateSignatures
:
for
t
in
forcefield
.
_templateSignatures
[
signature
]:
if
_matchResidue
(
residue
,
t
,
bondedToAtom
)
is
not
None
:
matchFound
=
True
if
matchFound
:
# Just copy the residue over.
for
atom
in
residue
.
atoms
():
newAtom
=
newTopology
.
addAtom
(
atom
.
name
,
atom
.
element
,
newResidue
)
newAtoms
[
atom
]
=
newAtom
newPositions
.
append
(
deepcopy
(
self
.
positions
[
atom
.
index
]))
else
:
# There's no matching template. Try to find one that matches based on everything except
# extra points.
template
=
None
residueNoEP
=
Residue
(
residue
.
name
,
residue
.
index
,
residue
.
chain
)
residueNoEP
.
_atoms
=
[
atom
for
atom
in
residue
.
atoms
()
if
atom
.
element
is
not
None
]
if
signature
in
forcefield
.
_templateSignatures
:
for
t
in
forcefield
.
_templateSignatures
[
signature
]:
if
t
in
templatesNoEP
:
matches
=
_matchResidue
(
residueNoEP
,
templatesNoEP
[
t
],
bondedToAtomNoEP
)
if
matches
is
not
None
:
template
=
t
;
# Record the corresponding atoms.
matchingAtoms
=
{}
for
atom
,
match
in
zip
(
residueNoEP
.
atoms
(),
matches
):
templateAtomName
=
t
.
atoms
[
match
].
name
for
templateAtom
in
template
.
atoms
:
if
templateAtom
.
name
==
templateAtomName
:
matchingAtoms
[
templateAtom
]
=
atom
break
if
template
is
None
:
raise
ValueError
(
'Residue %d (%s) does not match any template defined by the ForceField.'
%
(
residue
.
index
+
1
,
residue
.
name
))
# Add the regular atoms.
for
atom
in
residue
.
atoms
():
if
atom
.
element
is
not
None
:
newAtoms
[
atom
]
=
newTopology
.
addAtom
(
atom
.
name
,
atom
.
element
,
newResidue
)
newPositions
.
append
(
deepcopy
(
self
.
positions
[
atom
.
index
]))
# Add the extra points.
templateAtomPositions
=
len
(
template
.
atoms
)
*
[
None
]
for
index
,
atom
in
enumerate
(
template
.
atoms
):
if
atom
in
matchingAtoms
:
templateAtomPositions
[
index
]
=
self
.
positions
[
matchingAtoms
[
atom
].
index
]
for
index
,
atom
in
enumerate
(
template
.
atoms
):
if
atom
.
element
is
None
:
newTopology
.
addAtom
(
atom
.
name
,
None
,
newResidue
)
position
=
None
for
site
in
template
.
virtualSites
:
if
site
.
index
==
index
:
# This is a virtual site. Compute its position by the correct rule.
if
site
.
type
==
'average2'
:
position
=
site
.
weights
[
0
]
*
templateAtomPositions
[
index
+
site
.
atoms
[
0
]]
+
site
.
weights
[
1
]
*
templateAtomPositions
[
index
+
site
.
atoms
[
1
]]
elif
site
.
type
==
'average3'
:
position
=
site
.
weights
[
0
]
*
templateAtomPositions
[
index
+
site
.
atoms
[
0
]]
+
site
.
weights
[
1
]
*
templateAtomPositions
[
index
+
site
.
atoms
[
1
]]
+
site
.
weights
[
2
]
*
templateAtomPositions
[
index
+
site
.
atoms
[
2
]]
elif
site
.
type
==
'outOfPlane'
:
position
=
site
.
weights
[
0
]
*
templateAtomPositions
[
index
+
site
.
atoms
[
0
]]
+
site
.
weights
[
1
]
*
templateAtomPositions
[
index
+
site
.
atoms
[
1
]]
+
site
.
weights
[
2
]
*
templateAtomPositions
[
index
+
site
.
atoms
[
2
]]
if
position
is
None
and
atom
.
type
in
drudeTypeMap
:
# This is a Drude particle. Put it on top of its parent atom.
for
atom2
,
pos
in
zip
(
template
.
atoms
,
templateAtomPositions
):
if
atom2
.
type
in
drudeTypeMap
[
atom
.
type
]:
position
=
deepcopy
(
pos
)
if
position
is
None
:
# We couldn't figure out the correct position. As a wild guess, just put it at the center of the residue
# and hope that energy minimization will fix it.
knownPositions
=
[
x
for
x
in
templateAtomPositions
if
x
is
not
None
]
position
=
sum
(
knownPositions
)
/
len
(
knownPositions
)
newPositions
.
append
(
position
)
for
bond
in
self
.
topology
.
bonds
():
if
bond
[
0
]
in
newAtoms
and
bond
[
1
]
in
newAtoms
:
newTopology
.
addBond
(
newAtoms
[
bond
[
0
]],
newAtoms
[
bond
[
1
]])
self
.
topology
=
newTopology
self
.
positions
=
newPositions
\ No newline at end of file
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment