いつも勉強させていただいてます。
Win10にVirtual boxでCentOS7を入れて、AnacondaにてPython2.7とPython3を使いわけています。
以下の様に出力されるモジュールを作成しました。
これをテキストファイル出力または直接Pandasで処理していきたいと思っています。
In [81]: polarcontacts(filenames) (('complex.1-2', 787), ('complex.5', 1891)) (('complex.1-2', 788), ('complex.5', 1891)) (('complex.1-2', 1529), ('complex.1-2', 3803)) (('complex.1-2', 1529), ('complex.6', 1902)) (('complex.1-2', 1530), ('complex.1-2', 3803)) (('complex.1-2', 1530), ('complex.6', 1902)) (('complex.1-2', 1537), ('complex.1-2', 3804)) (('complex.1-2', 1537), ('complex.2', 1902)) (('complex.1-2', 1537), ('complex.5', 1899)) (('complex.1-2', 1537), ('complex.8', 1888)) (('complex.1-2', 1538), ('complex.1-2', 3804)) ・・・
そこで以下の様にtextというディレクトリを作成し、そこに書き込もうとしたのですが、Nonetypeのエラーが出ました。
In [88]: text="../polarcontacts.txt" In [89]: pc=polarcontacts(filenames) In [90]: with open (text,mode="w") as f: ...: f.write(pc) ...: --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-90-d1f2c6230c24> in <module> 1 with open (text,mode="w") as f: ----> 2 f.write(pc) 3 TypeError: write() argument must be str, not None In [91]: print(type(pc)) <class 'NoneType'>
strにするとエラーは出なくなるのですが、内容は書き込まれていないようでした。
In [92]: with open (text,mode="w") as f: ...: f.write(str(pc)) ...: In [94]: with open (text,mode="r") as f: ...: for row in f: ...: print (row.strip()) ...: ...: None
polarcontacts(filenames)をどのようにしたらテキストまたはCSVに保存してPandasで処理できるようにできるでしょうか。
初歩的な質問で申し訳ありませんが、お願いします。
以下Polarpairsに関しての追記です。
長くなるので省略しましたがご容赦ください。
https://pymolwiki.org/index.php/Polarpairs
上記サイトにて得られるモジュールなのですが、
Exampleの内容に入力pdbファイル情報やchain選択コマンドなどを加えPolarcontacts.pyとして保存して実行するようにしました。
Example内最終行のprint(p, 'Distance: %.2f' % (dist))はprint(p)に変えた出力が上記結果です。
細かく変更したので見落としがあるかもしれません。
Example pairs = polarpairs('chain A', 'chain B') for p in pairs: dist = cmd.get_distance('(%s`%s)' % p[0], '(%s`%s)' % p[1]) print(p, 'Distance: %.2f' % (dist)) The Script ''' (c) 2011 Thomas Holder, MPI for Developmental Biology ''' from pymol import cmd def polarpairs(sel1, sel2, cutoff=4.0, angle=63.0, name='', state=1, quiet=1): ''' ARGUMENTS sel1, sel2 = string: atom selections cutoff = float: distance cutoff angle = float: h-bond angle cutoff in degrees. If angle="default", take "h_bond_max_angle" setting. If angle=0, do not detect h-bonding. name = string: If given, also create a distance object for visual representation SEE ALSO cmd.find_pairs, cmd.distance ''' cutoff = float(cutoff) quiet = int(quiet) state = int(state) if angle == 'default': angle = cmd.get('h_bond_max_angle', cmd.get_object_list(sel1)[0]) angle = float(angle) mode = 1 if angle > 0 else 0 x = cmd.find_pairs('(%s) and donors' % sel1, '(%s) and acceptors' % sel2, state, state, cutoff=cutoff, mode=mode, angle=angle) + \ cmd.find_pairs('(%s) and acceptors' % sel1, '(%s) and donors' % sel2, state, state, cutoff=cutoff, mode=mode, angle=angle) x = sorted(set(x)) if not quiet: print('Settings: cutoff=%.1fangstrom angle=%.1fdegree' % (cutoff, angle)) print('Found %d polar contacts' % (len(x))) if len(name) > 0: for p in x: cmd.distance(name, '(%s`%s)' % p[0], '(%s`%s)' % p[1]) return x cmd.extend('polarpairs', polarpairs)
回答1件
あなたの回答
tips
プレビュー