Skip to content
Permalink
5ab4ed8e4a
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
23 lines (18 sloc) 866 Bytes
import sys
def remove_hydrogen_atoms(pdb_file_path, output_dir):
output_file_path = output_dir + pdb_file_path.replace('.pdb', '_no_hydrogen.pdb')
with open(pdb_file_path, 'r') as pdb_file, open(output_file_path, 'w') as output_file:
for line in pdb_file:
if line.startswith("ATOM") or line.startswith("HETATM"):
atom_name = line[12:16].strip() # Atom name field
if atom_name[0] == 'H':
continue # Skip hydrogen atoms
output_file.write(line)
print(f"Output file saved to: {output_file_path}")
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python script.py <pdb_file_path> <output_dir>")
sys.exit(1)
pdb_file_path = sys.argv[1]
output_dir = sys.argv[2]
remove_hydrogen_atoms(pdb_file_path, output_dir)