【问题标题】:The distance between the two interacting particles is smaller than cutoff distance两个相互作用粒子之间的距离小于截止距离
【发布时间】:2019-09-09 22:53:59
【问题描述】:

我收到此错误。具有多个元素的数组的真值是不明确的。使用 a.any() 或 a.all()

这是我的代码。我在函数“cal_total_pair_energy”rij

# Generate initial state
def generate_initial_coordinates(num_particles=100):
    coordinates = np.random.randint(num_particles, size=(3  , 3)) 
    return coordinates

def L_J_potential(rij):
    epsilon = 0.6
    sigma = 1.0
    V = 4.0 * epsilon * ((sigma / rij)**12 - (sigma / rij)**6)
    return V

def FENE_potential(rij):
    R = 0.3
    K = 40.0
    V_FENE = 0.5 * K * R**2.0 * np.log(1.0 - (rij / R)**2.0)
    return V_FENE

def particle_distance(r_i, r_j):
    rij = r_i - r_j
    return rij

def cal_total_pair_energy(coordinates, cutoff):
    e_nb = 0.0
    particle_count = len(coordinates)
    for i_particle in range(particle_count):
        for j_particle in range(i_particle):
            r_i = coordinates[i_particle]
            r_j = coordinates[j_particle]
            rij = particle_distance(r_i, r_j)

            if rij < cutoff:
                e_pair = L_J_potential(rij)
                e_nb += e_pair

    e_bond = 0.0
    for i_particle in range(particle_count-2):
        e_bond += FENE_potential(rij)

    e_tot = e_nb + e_bond
    return e_tot

sigma = 0.6
cutoff = 2.5 * sigma


【问题讨论】:

    标签: python montecarlo


    【解决方案1】:

    我相信r_ir_j 都是坐标数组,因此它们之间的距离不仅仅是差异,而是它的常态。因此:

    def particle_distance(r_i, r_j):
        rij = numpy.linalg.norm(r_i - r_j)
        return rij
    

    注意使用 numpy.linalg.norm。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      相关资源
      最近更新 更多