In [20]:
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
import particlesim.api
import particlesim.helpers_for_tests
from mpl_toolkits.mplot3d import Axes3D
In [21]:
def create_system_conf_with_na_and_cl(num_na, num_cl, box_size = 6):
particles = particlesim.helpers_for_tests.create_positions(box_size=box_size,number_of_particles=num_na+num_cl)
na = {'sigma':1.21496,'epsilon':0.0469,'charge':1}
cl = {'sigma':2.02234, 'epsilon':0.15,'charge':-1.0}
return particlesim.api.SystemConfiguration(xyz=particles,
sigmas=([na['sigma']]*num_na)+([cl['sigma']]*num_cl),
epsilons=[na['epsilon']]*num_na+[cl['epsilon']]*num_cl,
charges=[na['charge']]*num_na+[cl['charge']]*num_cl,
box_size=6)
In [22]:
def periodic_distance(part1,part2,box_size):
return np.linalg.norm(0.5 * box_size- (part1 - part2 + 0.5 * box_size) % box_size)
In [23]:
num_na_glob=20
num_cl_glob=20
box_size_glob = 6
system_conf = create_system_conf_with_na_and_cl(num_na=num_na_glob,num_cl=num_cl_glob, box_size = box_size_glob)
sampler = particlesim.api.Sampler(system_configuration=system_conf)
In [24]:
%%time
traj1,potential = sampler.metropolis(iteration_number=1000,beta=100)
In [25]:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
rang_of_samples = -1
ax.scatter(traj1[rang_of_samples:,:num_na_glob,0], traj1[rang_of_samples:,:num_na_glob,1], traj1[rang_of_samples:,:num_na_glob,2],c='r')
ax.scatter(traj1[rang_of_samples:,num_na_glob:,0], traj1[rang_of_samples:,num_na_glob:,1], traj1[rang_of_samples:,num_na_glob:,2],c='b')
ax.set_xlim([0,box_size_glob])
ax.set_ylim([0,box_size_glob])
ax.set_zlim([0,box_size_glob])
Out[25]:
In [27]:
%%time
system_conf._total_potential.longrange_energy(positions=system_conf.xyz)
Out[27]:
In [28]:
%%time
system_conf._total_potential.shortrange_energy(positions=system_conf.xyz)
Out[28]:
In [29]:
num_part = 100
num_na_glob=num_part//2
num_cl_glob=num_part//2
box_size_glob = 6
system_conf_test = create_system_conf_with_na_and_cl(num_na=num_na_glob,num_cl=num_cl_glob, box_size = box_size_glob)
In [30]:
%%time
for i in range(num_part):
system_conf_test._total_potential.shortrange.nlist.get_particles_within_radius(i)
In [31]:
%%time
system_conf_test._total_potential.shortrange_energy(positions=system_conf_test.xyz)
Out[31]:
In [ ]: