0

私の関数は、モンテカルロ積分法を使用した pi 値の決定に似ています。この関数は、基本的に分子をランダムな位置に挿入し、エネルギーを推定します。マルチプロセッシング モジュールを使用して、関数内の for ループを複数のコアで動作するように変換します。ただし、すべてのプロセスの乱数ジェネレーターとエネルギー値から同様の値を取得しました。関数を複数回実行したようですが、同様の結果が報告されています。

ユーザー定義関数のリスト。簡単にするために詳細は与えられていません。

def createRandomValuesforRotationTranslation(boxSpace):
def rotateTranslateMolec(randomValues,molec):
def makemolgroups(newMolec,peg):
def steric_closmol_clashes_vdw2(boxMolecs,ResID):

for ループを実行します。

nReplicates = 100 
count = 0
throws = 0

for i in range(nReplicates):
    throws += 1
    randomvalues = createRandomValuesforRotationTranslation(boxSpace)
    newMolec = rotateTranslateMolec(randomvalues,rna_mol)
    boxMolecs = makemolgroups(newMolec,peg)
    output = steric_closmol_clashes_vdw2(boxMolecs,ResID)
    count += output
    ratio = count /throws
    # binomial distribution method V_free = (number of accepted/total)Vbox 
    V_free = (count/throws)*output_vol
    p = count/throws
    std_binom = sqrt(throws*p*(1-p))
    error_binom = (output_vol/throws)*std_binom
    error_binom_fraction =  error_binom/V_free
    if i % 1 == 0:
        print("STEPS %d: BINOMIAL ERROR T.VOLUME %s: ERROR F.VOLUME %s: ESTIMATED VOLUME %s:" %(i, error_binom,error_binom_fraction,ratio))

次に、for ループを次のように変換します。

def paralle_distances(nReplicates): 
    count = 0
    throws = 0
    for i in range(nReplicates):
        throws += 1
        randomvalues = createRandomValuesforRotationTranslation(boxSpace)
        newMolec = rotateTranslateMolec(randomvalues,rna_mol)
        boxMolecs = makemolgroups(newMolec,peg)
        output = steric_closmol_clashes_vdw2(boxMolecs,ResID)
        count += output
        ratio = count /throws
        # binomial distribution method V_free = (number of accepted/total)Vbox 
        V_free = (count/throws)*output_vol
        p = count/throws
        std_binom = sqrt(throws*p*(1-p))
        error_binom = (output_vol/throws)*std_binom
        error_binom_fraction =  error_binom/V_free
        if i % 1 == 0:
            print("STEPS %d: BINOMIAL ERROR T.VOLUME %s: ERROR F.VOLUME %s: ESTIMATED VOLUME %s:" %(i, error_binom,error_binom_fraction,ratio))
    return

import multiprocessing as mp
pool = mp.Pool(processes=4)
results = [pool.apply_async(paralle_distances, args=(x,)) for x in range(1,5)]

ここでのみランダムな位置の値を出力しました。

(( 242.281, -50.4288, -7.54141 ), ( -0.679886, 0.674784, 0.287092 ), 201.097 degree)
(( 242.281, -50.4288, -7.54141 ), ( -0.679886, 0.674784, 0.287092 ), 201.097 degree)
(( 242.281, -50.4288, -7.54141 ), ( -0.679886, 0.674784, 0.287092 ), 201.097 degree)
(( 157.376, 67.453, -132.227 ), ( 0.0216526, 0.765258, 0.64336 ), 16.5297 degree)
(( 157.376, 67.453, -132.227 ), ( 0.0216526, 0.765258, 0.64336 ), 16.5297 degree)
(( 242.281, -50.4288, -7.54141 ), ( -0.679886, 0.674784, 0.287092 ), 201.097 degree)

どうもありがとう!

4

1 に答える 1