第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何根據(jù)通過熊貓從LAMMPS輸出文件導(dǎo)入的鍵合數(shù)據(jù)將原子細(xì)分為三組?

如何根據(jù)通過熊貓從LAMMPS輸出文件導(dǎo)入的鍵合數(shù)據(jù)將原子細(xì)分為三組?

慕田峪9158850 2022-09-27 09:55:37
我是編程和分子動(dòng)力學(xué)模擬的新手。我正在使用LAMMPS來模擬物理氣相沉積(PVD)過程,并確定不同時(shí)間步長中原子之間的相互作用。在我執(zhí)行分子動(dòng)力學(xué)模擬后,LAMMPS為我提供了一個(gè)輸出鍵文件,其中包含每個(gè)單個(gè)原子的記錄(作為原子ID),它們的類型(向特定元素的編號(hào)),以及與這些特定原子鍵合的其他原子的信息。 典型的債券文件如下所示。我的目標(biāo)是根據(jù)原子的類型(如組1:氧-氫-氫)對(duì)原子進(jìn)行三組分類,方法是考慮它們從鍵輸出文件中的鍵合信息,并計(jì)算每個(gè)時(shí)間步長的組數(shù)。我使用熊貓,并為每個(gè)時(shí)間步長創(chuàng)建了一個(gè)數(shù)據(jù)幀。df = pd.read_table(directory, comment="#", delim_whitespace= True, header=None, usecols=[0,1,2,3,4,5,6] )headers= ["ID","Type","NofB","bondID_1","bondID_2","bondID_3","bondID_4"]df.columns = headersdf.fillna(0,inplace=True)df = df.astype(int)timestep = int(input("Number of Timesteps: ")) #To display desired number of timesteps.total_atom_number = 53924 #Total number of atoms in the simulation.t= 0 #code starts from 0th timestep.firstTime = []while(t <= timestep):    open('file.txt', 'w').close() #In while loop = displays every timestep individually, Out of the while loop = displays results cumulatively.    i = 0    df_tablo =(df[total_atom_number*t:total_atom_number*(t+1)]) #Creates a new dataframe that inlucdes only t'th timestep.    df_tablo.reset_index(inplace=True)    print(df_tablo)請參閱此示例,該示例說明了我對(duì) 3 個(gè)原子進(jìn)行分組的算法。鍵合列顯示與其行中的原子鍵合在一起的不同原子(按原子 ID)。例如,通過使用該算法,我們可以對(duì)[1,2,5]和[1,2,6]進(jìn)行分組,但不能對(duì)[1,2,1]進(jìn)行分組,因?yàn)樵硬荒芘c自身建立鍵。此外,我們可以在分組后將這些原子ID(第一列)轉(zhuǎn)換為它們的原子類型(第二列),例如[1,3,7]到[1,1,3]。通過遵循上面提到的鍵,1)我可以成功地將原子相對(duì)于它們的ID分組,2)將它們轉(zhuǎn)換為它們的原子類型,3)分別計(jì)算每個(gè)時(shí)間步中存在的組數(shù)。第一個(gè) while 循環(huán)(上圖)計(jì)算每個(gè)時(shí)間步的組,而第二個(gè) while 循環(huán)(下圖)將每行中的原子(等于存在的每個(gè)原子 ID)與數(shù)據(jù)幀中不同行的相應(yīng)綁定原子進(jìn)行分組。
查看完整描述

1 回答

?
繁星coding

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊

我不確定我是否理解了邏輯,看看這是否有幫助。


對(duì)于100000三重奏,需要41秒。


loc,get_loc是非常廣泛的操作,所以把你的表放在字典里,而不是驗(yàn)證一切都是唯一的,把它放在一個(gè)集合中


import pandas as pd

import random

from collections import defaultdict as dd

from collections import Counter

import time


# create 100000 unique trios of numbers

ids = list(range(50000))

trios_set = set()

while len(trios_set)<100000:

    trio = random.sample(ids,3)

    trios_set.add(frozenset(trio))


ids_dict = dd(list)  # a dictionery where id is the key and value is all the id who are partner with it in a list


for s in trios_set:

    for id in s:

        for other_id in s:

            if id!= other_id:

                ids_dict[id].append(other_id)


ids_dict = dict(ids_dict)

for_df = []

type_list = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n"] 

for id in ids_dict:

    massage = {}

    massage["id"] = id

    other_id_index = 1

    for other_id in ids_dict[id]:

        massage["id_"+str(other_id_index)] =  other_id

        other_id_index+=1

    massage["type"] = random.choice(type_list)

    for_df.append(massage)


df = pd.DataFrame(for_df) # a table with id column and all ids who are with it in trios in id_1 id_2.. and type column with a letter


#------------------------------------------------------------------

#till here we built the input table

start_time = time.time() #till here we build the input table, now check the time for 100000 atoms

type_dict = {}

from_df = dd(set)


for i,r in df.iterrows(): #move the dataframe to a dict of id as key and value as list of ids who connected to it

    for col in df:

        if "id_"in col and str(r[col])!="nan":

            from_df[r["id"]].add(r[col])

    type_dict[r["id"]] = r["type"] #save the type of id in a dictionery


from_df = dict(from_df)

out_trio_set = set() 


for id in from_df:

    for other_id in from_df[id]:

        if other_id!= id and str(other_id)!="nan":

            for third_id in from_df[other_id]:

                current_trio = frozenset([id, other_id,third_id])

                if len(current_trio)==3:

                    out_trio_set.add(current_trio)


type_conter = Counter()


for trio in out_trio_set:

    type_list = []

    for id in trio:

        type_list.append(type_dict[id])

    type_list = sorted(type_list)

    atom_type = "".join(type_list)

    type_conter[atom_type] +=1


out_df = pd.DataFrame(type_conter, index = [1]) # in here put index as timestamp


out_df.to_excel(r"D:\atom.xlsx")

print("--- %s seconds ---" % (time.time() - start_time))


查看完整回答
反對(duì) 回復(fù) 2022-09-27
  • 1 回答
  • 0 關(guān)注
  • 163 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)