我有一个file.txt形式:; In this topology include file, you will find position restraint
; entries for all the heavy atoms in your original pdb file.
; This means that all the protons which were added by pdb2gmx are
; not restrained.
[ position_restraints ]
; atom type fx fy fz
1 1 1000 1000 1000
5 1 1000 1000 1000
7 1 1000 1000 1000
10 1 1000 1000 1000
12 1 1000 1000 1000
13 1 1000 1000 1000
14 1 1000 1000 1000
16 1 1000 1000 1000
(如果您感兴趣,这是来自gromacs的位置限制文件)
在Python中,我有一个数字阵列整数[2, 4, 7, 8, 9, 10, 15, 108]。我想将file.txt替换为:
^{pr2}$
也就是说,file.txt内的表的第一列将被我在Python中定义的整数数组替换。请注意列中的对齐方式是如何被尊重的。这很重要。在
我该怎么做?我在问题标题中使用了numpy.savetxt,因为它与我想做的很接近,但我认为{}本身无法做到。在
我该怎么做?在