def pdb_from_file(path, hydrogenate=True, clean=True) -> Pdb: """Construct Pdb object from a PDB file Args: path: Path to PDB file hydrogenate: Whether to add hydrogens clean: Whether to remove unwanted molecules Returns: Protein databank entry """ pdb = atomium.pdb_from_file(path) return pdb_from_atomium_pdb(pdb, hydrogenate, clean)
def test_model_saving(self): model = Model() atom1 = Atom("N", 12.0, 11.5, 1.5) atom2 = Atom("C", 12.5, 10, 2, id=102, bfactor=22.1) model.add_atom(atom1) model.add_atom(atom2) model.save("tests/integration/files/model.xyz", description="Some atoms") new = atomium.xyz_from_file("tests/integration/files/model.xyz") self.assertEqual(new.title, "Some atoms") self.assertEqual(len(new.model.atoms()), 2) self.assertEqual(new.model.atom(element="N").location, (12, 11.5, 1.5)) self.assertEqual(new.model.atom(element="C").location, (12.5, 10, 2)) model.save("tests/integration/files/model.pdb", description="Some atoms") new = atomium.pdb_from_file("tests/integration/files/model.pdb") self.assertEqual(new.title, "Some atoms") self.assertEqual(len(new.model.atoms()), 2) self.assertEqual(new.model.atom(0).location, (12, 11.5, 1.5)) self.assertEqual(new.model.atom(102).bfactor, 22.1)
#! /usr/bin/env python3 import atomium import biometal import sys import matplotlib.pyplot as plt if len(sys.argv) == 1: print("Please provide a PDB and ion") sys.exit() pdbs = [] for arg in sys.argv[1:-2]: pdb, atom_id = arg.split(":") model = atomium.pdb_from_file(pdb + ".pdb").model pdbs.append({"model": model, "atom": model.atom(id=int(atom_id))}) radius = float(sys.argv[-2]) step = float(sys.argv[-1]) x = [0.5] while x[-1] < radius: x.append(round(x[-1] + step, 6)) ys = [] for pdb in pdbs: ys.append([ biometal.hydrophobic_contrast( pdb["model"], *pdb["atom"].location, radius, metal=False, pc=False) / 1000 for radius in x ])
files = os.listdir(location) scores = [f for f in files if f.endswith("_scores.dat")] os.chdir(location) print("There are {} PDBs with scores".format(len(scores))) print("PDB\tPoints\tIon\tRank\tDev.\tScore\tRange") for scores_file in scores: pdb_file = scores_file.replace("_scores.dat", ".pdb") with open(scores_file) as f: lines = f.read().splitlines() lines = [[float(val) for val in line.split()] for line in lines[1:]] point_count = len(lines) - 1 model = atomium.pdb_from_file(pdb_file).model metals = model.atoms() - model.atoms(metal=False) for i, metal in enumerate(metals): point = [line for line in lines if metal.distance_to(line[:3]) <= 3][-1] deviation = metal.distance_to(point[:3]) print("{}\t{}\t{}\t{}\t{}\t{}\t{}{}{}".format( pdb_file[:-4] if i == 0 else "", point_count if i == 0 else "", metal.element, len(lines) - lines.index(point), round(deviation, 1), round(point[-1] / 1000, 1), round(max([l[-1] for l in lines]) / 1000, 1) if i == 0 else "", "/" if i == 0 else "", round(min([l[-1] for l in lines]) / 1000, 1) if i == 0 else ""
import sys sys.path.insert(0, ".") import atomium pdb = atomium.pdb_from_file("tests/time/{}.pdb") pdb.save("tests/time/temp.pdb")