8
$\begingroup$

I have a PDB file. I want to duplicate this pdb file automatically instead of doing it manually. For example, if I visualize my PDB, I will find only one structure in (x,y,z). I want to have more copies of my structure. Therefore, I can visualize the PDB, and I can see that there are 9 or 10 copies of the structure in the PDB file, and they are located well close to each other but do not overlap. Then I can solvate without any problem. Is there any Python code or method to do that?

$\endgroup$
4
  • $\begingroup$ This is tricky. Having one file where the atoms are near one each other normally give errors. $\endgroup$
    – Camps
    Apr 24, 2023 at 19:31
  • $\begingroup$ Not the atoms, I mean the whole structure. For example the distance between each structure 3 A and the position is randomly. But not so far from each other. $\endgroup$ Apr 24, 2023 at 19:56
  • 1
    $\begingroup$ @Abd-ElazeemMohamed How about using a software called Packmol, where you can put multiple copies of molecules in a box (you need to specify the box size) with a distance tolerance of x ang between any two molecules . $\endgroup$
    – Vasista
    Apr 24, 2023 at 20:10
  • $\begingroup$ @Vasista. Yes, I checked and this is what I want. Thanks. You can write it as an answer $\endgroup$ Apr 25, 2023 at 9:53

3 Answers 3

9
$\begingroup$

You can use Packmol to achieve this. Below is an example script

tolerance 15.0

# The file type of input and output files is PDB

filetype pdb

# The name of the output file

output 20_pq_5jb.pdb

structure polyq_frame_1470.pdb
  number 20
  inside box 0. 0. 0. 200. 200. 200.
end structure

tolerance 10

structure sim10_frame_1158.pdb
  number 5
  inside box 0. 0. 0. 200. 200. 200.
end structure

This script can put 20 molecules of type A and five molecules of type B in a box of size 200x200x200.

$\endgroup$
1
8
$\begingroup$

This can also be done in VMD using Tcl scripts. The only requirements are that you have a PSF and PDB file for the structure that you want to replicate.

set pdb methanol.pdb    # name of pdb file
set psf methanol.psf    # name of psf file

set a 3 # repetitions in x-direction
set b 3 # repetitions in y-direction
set c 3 # repetitions in z-direction

set xdist 10    # separation in x-direction
set ydist 10    # separation in y-direction
set zdist 10    # separation in z-direction

set xend [expr $a / 2]
set xstart [expr -1 * $xend]

set yend [expr $b / 2]
set ystart [expr -1 * $yend]

set zend [expr $c / 2]
set zstart [expr -1 * $zend]

set counter 0

# generate the required psf and pdb files

for { set i $xstart } { $i <= $xend } { incr i } {
    set xtrans [expr $xdist * $i]
    for { set j $ystart } { $j <= $yend } { incr j } {
        set ytrans [expr $ydist * $j]
        for { set k $zstart } { $k <= $zend } { incr k } {
            set ztrans [expr $zdist * $k]
            mol load psf $psf
            mol addfile $pdb type pdb waitfor all
            set sel [atomselect top all]    # assuming that your pdb file contains only the molecule that you want to replicate
            $sel moveby [vecscale -1 [measure center $sel weight mass]] # moves the molecule to origin
            set transvec [list $xtrans $ytrans $ztrans]
            $sel moveby $transvec
            $sel set segname M$counter
            $sel writepdb methanol.$i.$j.$k.pdb
            $sel writepsf methanol.$i.$j.$k.psf
            incr counter
            mol delete all
        }
    }
}

# merge the generated files

package require topotools 1.6

set molList {}

for { set i $xstart } { $i <= $xend } { incr i } {
for { set j $ystart } { $j <= $yend } { incr j } {
    for { set k $zstart } { $k <= $zend } { incr k } {
        set mol [mol new methanol.$i.$j.$k.psf waitfor all]
        $mol addfile methanol.$i.$j.$k.pdb
        lappend molList $mol                
        }
    }
}

set mol [::TopoTools::mergemols $molList]
animate write pdb combined.pdb $mol
animate write psf combined.psf $mol
$\endgroup$
1
  • 1
    $\begingroup$ Perfect. Thanks for you help $\endgroup$ Apr 25, 2023 at 15:43
7
$\begingroup$

This can be achieved with Python. I will demonstrate it with a simple molecule : methanol.

The PDB file of methanol I used looks like this:

COMPND      METHANOL
ATOM      1  C           1      -0.748  -0.015   0.024  1.00  0.00
ATOM      2  O           1       0.558   0.420  -0.278  1.00  0.00
ATOM      3  H           1      -1.293  -0.202  -0.901  1.00  0.00
ATOM      4  H           1      -1.263   0.754   0.600  1.00  0.00
ATOM      5  H           1      -0.699  -0.934   0.609  1.00  0.00
ATOM      6  H           1       0.716   1.404   0.137  1.00  0.00
TER       6              1
END

Let us initialize some paths and variables:

input_pdb_path = 'input/methanol.pdb'
output_pdb_with_repeated_mols = 'output/methanol_repeated.pdb'
n_mols = 10

Let us now read the PDB which we wish to repeat.

with open(input_pdb_path, 'r') as in_file:
    data = in_file.read()

A new PDB will be created at the output path defined in the initialization. Since you require that the molecules are not overlapping, let us translate them in the z axis by 1 unit from each other.

This is achieved by the following function:

def translate_mol_in_z_axis(data, translation_dist):
  pattern = r'-?[\d]*[.][\d]+' # This pattern will capture any numbers with decimals digits
  edited_lines = []
  n_decimal_places  =3

  for line in data.split('\n'):
    numeric_info = [(m.start(0), m.end(0), m.group(0)) for m in re.finditer(pattern, line)]
    if numeric_info:
      x_coord_info = numeric_info[0]
      y_coord_info = numeric_info[1]
      z_coord_info = numeric_info[2]

      z_coord_start_idx= z_coord_info[0]
      z_coord_end_idx= z_coord_info[1]
      z_coord_val = z_coord_info[2]

      line_edited = line[:z_coord_start_idx] + str(round(float(z_coord_val)+translation_dist, n_decimal_places)) + line[z_coord_end_idx+1:]
    else:
      line_edited = line
    
    edited_lines.append(line_edited)

  edited_mol_pdb = '\n'.join(edited_lines)
  return edited_mol_pdb

Let us now replicate the molecules in a new output file:

with open(output_pdb_with_repeated_mols, 'w') as out_file:
  for i in range(n_mols):
    translation_dist = i 
    out_file.write('\n\n')
    translated_mol_data = translate_mol_in_z_axis(data, translation_dist)
    out_file.write(translated_mol_data)

When the output PDB is viewed in a software like PyMOL, you will see that the molecules are stacked with 1 unit distance in the z axis like this:

stacked_molecules_PDB

The output file will look like this:

COMPND      METHANOL
ATOM      1  C           1      -0.748  -0.015   0.024 1.00  0.00
ATOM      2  O           1       0.558   0.420  -0.278 1.00  0.00
ATOM      3  H           1      -1.293  -0.202  -0.901 1.00  0.00
ATOM      4  H           1      -1.263   0.754   0.6 1.00  0.00
ATOM      5  H           1      -0.699  -0.934   0.609 1.00  0.00
ATOM      6  H           1       0.716   1.404   0.137 1.00  0.00
TER       6              1
END


COMPND      METHANOL
ATOM      1  C           1      -0.748  -0.015   1.024 1.00  0.00
ATOM      2  O           1       0.558   0.420  0.722 1.00  0.00
ATOM      3  H           1      -1.293  -0.202  0.099 1.00  0.00
ATOM      4  H           1      -1.263   0.754   1.6 1.00  0.00
ATOM      5  H           1      -0.699  -0.934   1.609 1.00  0.00
ATOM      6  H           1       0.716   1.404   1.137 1.00  0.00
TER       6              1
END


COMPND      METHANOL
ATOM      1  C           1      -0.748  -0.015   2.024 1.00  0.00
ATOM      2  O           1       0.558   0.420  1.722 1.00  0.00
ATOM      3  H           1      -1.293  -0.202  1.099 1.00  0.00
ATOM      4  H           1      -1.263   0.754   2.6 1.00  0.00
ATOM      5  H           1      -0.699  -0.934   2.609 1.00  0.00
ATOM      6  H           1       0.716   1.404   2.137 1.00  0.00
TER       6              1
END


COMPND      METHANOL
ATOM      1  C           1      -0.748  -0.015   3.024 1.00  0.00
ATOM      2  O           1       0.558   0.420  2.722 1.00  0.00
ATOM      3  H           1      -1.293  -0.202  2.099 1.00  0.00
ATOM      4  H           1      -1.263   0.754   3.6 1.00  0.00
ATOM      5  H           1      -0.699  -0.934   3.609 1.00  0.00
ATOM      6  H           1       0.716   1.404   3.137 1.00  0.00
TER       6              1
END


COMPND      METHANOL
ATOM      1  C           1      -0.748  -0.015   4.024 1.00  0.00
ATOM      2  O           1       0.558   0.420  3.722 1.00  0.00
ATOM      3  H           1      -1.293  -0.202  3.099 1.00  0.00
ATOM      4  H           1      -1.263   0.754   4.6 1.00  0.00
ATOM      5  H           1      -0.699  -0.934   4.609 1.00  0.00
ATOM      6  H           1       0.716   1.404   4.137 1.00  0.00
TER       6              1
END


COMPND      METHANOL
ATOM      1  C           1      -0.748  -0.015   5.024 1.00  0.00
ATOM      2  O           1       0.558   0.420  4.722 1.00  0.00
ATOM      3  H           1      -1.293  -0.202  4.099 1.00  0.00
ATOM      4  H           1      -1.263   0.754   5.6 1.00  0.00
ATOM      5  H           1      -0.699  -0.934   5.609 1.00  0.00
ATOM      6  H           1       0.716   1.404   5.137 1.00  0.00
TER       6              1
END


COMPND      METHANOL
ATOM      1  C           1      -0.748  -0.015   6.024 1.00  0.00
ATOM      2  O           1       0.558   0.420  5.722 1.00  0.00
ATOM      3  H           1      -1.293  -0.202  5.099 1.00  0.00
ATOM      4  H           1      -1.263   0.754   6.6 1.00  0.00
ATOM      5  H           1      -0.699  -0.934   6.609 1.00  0.00
ATOM      6  H           1       0.716   1.404   6.137 1.00  0.00
TER       6              1
END


COMPND      METHANOL
ATOM      1  C           1      -0.748  -0.015   7.024 1.00  0.00
ATOM      2  O           1       0.558   0.420  6.722 1.00  0.00
ATOM      3  H           1      -1.293  -0.202  6.099 1.00  0.00
ATOM      4  H           1      -1.263   0.754   7.6 1.00  0.00
ATOM      5  H           1      -0.699  -0.934   7.609 1.00  0.00
ATOM      6  H           1       0.716   1.404   7.137 1.00  0.00
TER       6              1
END


COMPND      METHANOL
ATOM      1  C           1      -0.748  -0.015   8.024 1.00  0.00
ATOM      2  O           1       0.558   0.420  7.722 1.00  0.00
ATOM      3  H           1      -1.293  -0.202  7.099 1.00  0.00
ATOM      4  H           1      -1.263   0.754   8.6 1.00  0.00
ATOM      5  H           1      -0.699  -0.934   8.609 1.00  0.00
ATOM      6  H           1       0.716   1.404   8.137 1.00  0.00
TER       6              1
END


COMPND      METHANOL
ATOM      1  C           1      -0.748  -0.015   9.024 1.00  0.00
ATOM      2  O           1       0.558   0.420  8.722 1.00  0.00
ATOM      3  H           1      -1.293  -0.202  8.099 1.00  0.00
ATOM      4  H           1      -1.263   0.754   9.6 1.00  0.00
ATOM      5  H           1      -0.699  -0.934   9.609 1.00  0.00
ATOM      6  H           1       0.716   1.404   9.137 1.00  0.00
TER       6              1
END
$\endgroup$
2
  • $\begingroup$ Perfect. Thanks for your help $\endgroup$ Apr 25, 2023 at 15:43
  • $\begingroup$ @Abd-ElazeemMohamed if my answer helped you, then please consider upvoting $\endgroup$ Apr 25, 2023 at 16:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .