Malloc error
Posted: Thu May 30, 2019 9:07 am
I've been playing with coulomb gases, and I got the following (mysterious) error when performing simulation.minimizeEnergy():
What makes this "mysterious" is that it is sensitive to the initial configuration of my atoms. I get crashes in some cases, and it works fine in others.
My full code is:
Code: Select all
python(7187,0x1093785c0) malloc: *** error for object 0x7fe32d3871f8: pointer being freed was not allocated
python(7187,0x1093785c0) malloc: *** set a breakpoint in malloc_error_break to debug
Abort trap: 6
My full code is:
Code: Select all
from simtk import openmm, unit
from simtk.openmm import app
import numpy as np
nparticles = 7
mass = 1.0 * unit.amu
charge = 0.1 * unit.elementary_charge
sigma = 1.0 * unit.nanometer
epsilon = 0.0 * unit.kilojoule_per_mole
dt = 0.001 * unit.picosecond
gamma = 1/unit.picosecond
temp =300 * unit.kelvin
system = openmm.System()
for index in range(nparticles):
system.addParticle(mass)
coulomb_force = openmm.NonbondedForce()
coulomb_force.setNonbondedMethod(openmm.NonbondedForce.NoCutoff)
for index in range(nparticles):
coulomb_force.addParticle(charge, sigma, epsilon)
coulomb_force_index = system.addForce(coulomb_force)
trapping_force = openmm.CustomExternalForce("10 * r^2; r=sqrt(x*x+y*y+z*z)");
for i in range(nparticles):
trapping_force.addParticle(i, [])
trapping_force_index = system.addForce(trapping_force)
# this causes an malloc error
center = np.array([[0.0,0.0,0.0]])
# this works fine
#center = np.array([[0.01,0.01,0.0]])
positions = np.copy(center)
for j in range(nparticles-1):
positions = np.append(positions, center
+ 2.0 * np.array([[np.cos(2*j * np.pi/(nparticles-1)),
np.sin(2*j * np.pi/(nparticles-1)), 0.0]]),axis=0)
topology = app.Topology()
element = app.Element.getBySymbol('H')
chain = topology.addChain()
for particle in range(system.getNumParticles()):
residue = topology.addResidue('H', chain)
topology.addAtom('H', element, residue)
# this is arbitrary
integrator = openmm.BrownianIntegrator(temp,gamma, dt)
simulation = app.Simulation(topology, system, integrator)
simulation.context.setPositions(positions)
state = simulation.context.getState(getEnergy=True)
potential_energy =state.getPotentialEnergy()
print('Intitial potential energy: %s' % potential_energy)
simulation.minimizeEnergy()
state = simulation.context.getState(getEnergy=True)
potential_energy =state.getPotentialEnergy()
print('Minimized potential energy: %s' % potential_energy)