<< Adding charges to PDB >>

24 views
Skip to first unread message

I. Camps

unread,
Nov 8, 2023, 1:41:20 PM11/8/23
to MDnalysis discussion

Hi,

I did some calculations using a PDB file as input. As a result, I got a file with the atomic partial charges (only the values in one column, no other information) and the output PDB file structure without the charge information.

My question: Is there a function that permit me to add the charges to the output PDB file using the separate file?


Regards,


Camps

Hugo Macdermott-Opeskin

unread,
Nov 8, 2023, 4:06:48 PM11/8/23
to MDnalysis discussion
Hi Camps, 

The PDB B-factor field is commonly used for this (and will allow you to colour by charge). 

See this fantastic tutorial by @orbeckst: https://gist.github.com/orbeckst/6bea4a4be3ad0eb541e105edd58e93bf

Cheers, 

Hugo


I. Camps

unread,
Nov 13, 2023, 3:16:42 PM11/13/23
to MDnalysis discussion
Thank you very much.

But I needed to add the charge in the correct place, as a third-party application will use such information.

I also asked for help at Bioinformatics Stack Exchange forum, and got the answer below for a working Python code:

######
pdb = 'input_connect.pdb'
charges = 'sistema20.charges'
charges_list = []

with open(charges , 'r') as handle :
    for i in handle.readlines() :
        charges_list.append(i.strip())
print(charges_list)

with open(pdb , 'r') as handle :
    pdb_file = handle.readlines()
print(pdb_file)

idx = 0
with open('result_python.pdb' , 'w') as handle :
    for i in pdb_file :
        i = i.strip()
        if i[0:6] == 'HETATM' :
            i = i +'  '+  charges_list[idx] +'\n'
            idx += 1
            handle.writelines(i)
        else :
            i = i + '\n'
            handle.writelines(i)
######

Reply all
Reply to author
Forward
0 new messages