【发布时间】:2017-04-07 16:07:51
【问题描述】:
我有一个代码可以从这个输入文件计算 3D 坐标的距离公式
input_file="mock_data.csv"
cmd=pd.read_csv(input_file)
subset = cmd[['carbon','x_coord', 'y_coord','z_coord']]
coordinate_values = [tuple(x) for x in subset.values]
atoms = coordinate_values
atomPairs = itertools.combinations(atoms, 2)
for pair in atomPairs:
x1 = pair[0][1]
y1 = pair[0][2]
z1 = pair[0][3]
x2 = pair[1][1]
y2 = pair[1][2]
z2 = pair[1][3]
"""Define the values for the distance between the atoms"""
def calculate_distance(x1,y1,x2,y2,z1,z2):
dist=math.sqrt((x2 - x1)**2 + (y2 - y1)**2 + (z2-z1)**2)
return dist
d=calculate_distance(x1,y1,x2,y2,z1,z2)
我目前已经编写了代码来计算每个“碳”之间的距离。我的问题是我的坐标都是绝对值 - 每个坐标都可以是正数或负数。我想计算所有可能坐标的每个碳之间的距离,即每个 3D 坐标的所有正负组合。
简单示例:“碳”1 的坐标为 (1.08, 0.49, 0.523),但也可以是 (-1.08, -0.49, -0.523), (-1.08, 0.49, 0.523), (-1.08, -0.49 , 0.523), (-1.08, 0.49, -0.523), (1.08, -0.49, 0.523), (1.08, -0.49, -0.523), (1.08, 0.49, -0.523),总共有八种可能性每个坐标系。
我需要一个代码来遍历所有这些可能的坐标值来计算我已经编码的距离。
【问题讨论】:
-
欢迎来到 StackOverflow。请阅读并遵循帮助文档中的发布指南。 on topic 和 how to ask 在这里申请。 StackOverflow 不是设计、编码、研究或教程服务。
-
创建一些包含所有所需坐标的列表,并使用
itertools.product获取笛卡尔积。
标签: python coordinates combinations