예제 #1
0
    def test_atom_populate(self):
        db_entry = {
            "type": "type",
            "mass": 1,
            "charge": -1,
            "sigma": 0.5,
            "epsilon": -0.5,
            "dipole": 0,
            "diameter": 1,
            "rotmass": -1
        }
        atom1 = Atom(**db_entry)
        atom2 = Atom(name="name", resname="resname",
                     resid=1, x=0.5, y=0.5, z=0.5)
        atom1.populate(atom2)

        self.assertEqual(atom1.name, "name")
        self.assertEqual(atom1.type, "type")
        self.assertEqual(atom1.resname, "resname")
        self.assertEqual(atom1.resid, 1)
        self.assertEqual(atom1.x, 0.5)
        self.assertEqual(atom1.y, 0.5)
        self.assertEqual(atom1.z, 0.5)
        self.assertEqual(atom1.diameter, 1)
        self.assertEqual(atom1.rotmass, -1)
        self.assertEqual(atom1.charge, -1)
        self.assertEqual(atom1.mass, 1)
        self.assertEqual(atom1.sigma, 0.5)
        self.assertEqual(atom1.epsilon, -0.5)
        self.assertEqual(atom1.dipole, 0)
예제 #2
0
    def __init__(self, filename):
        super(GROReader, self).__init__()

        with open(filename) as f:
            last_resid = -1
            self.comment = f.readline()
            natoms = int(f.readline())

            for i in range(natoms):
                line = f.readline()
                self.atoms.append(
                    Atom(name=line[10:15].strip(),
                         resname=line[5:10].strip(),
                         resid=int(line[0:5]),
                         x=10 * float(line[20:28]),
                         y=10 * float(line[28:36]),
                         z=10 * float(line[36:44])))
                if self.atoms[-1].resid != last_resid:
                    self.molecules.append(Molecule(self.atoms[-1].resname, []))
                    last_resid = self.atoms[-1].resid
                self.molecules[-1].atoms.append(int(line[15:20]) - 1)

            line = f.readline()
            self.cell = [
                10 * float(line[0:10]), 10 * float(line[10:20]),
                10 * float(line[20:30])
            ]
예제 #3
0
    def __init__(self, filename):
        super(PDBReader, self).__init__()

        with open(filename) as f:
            last_resid = -1

            for line in f:
                if line.startswith("ATOM  "):
                    self.atoms.append(
                        Atom(name=line[13:17].strip(),
                             resname=line[17:21].strip(),
                             resid=int(line[22:26]),
                             x=float(line[30:38]),
                             y=float(line[38:46]),
                             z=float(line[46:54])))
                    if self.atoms[-1].resid != last_resid:
                        self.molecules.append(
                            Molecule(self.atoms[-1].resname, []))
                        last_resid = self.atoms[-1].resid
                    self.molecules[-1].atoms.append(int(line[6:11]) - 1)

                if line.startswith("CRYST1"):
                    self.cell = [
                        float(line[6:15]),
                        float(line[15:24]),
                        float(line[24:33]),
                        float(line[33:40]),
                        float(line[40:47]),
                        float(line[47:54])
                    ]
예제 #4
0
    def __init__(self, filename=None):
        """
        Create a new AtomDatabase object

        Args:
            filename: Name of atom database file to open.
        """
        if filename is None:
            filename = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                    os.path.join("data", "atoms.json"))

        db = Parser(filename)
        self.atoms = {}
        self._lj_table_eps = defaultdict(dict)

        # Read atom types
        for name, data in db.atoms.items():
            if "rotmass" not in data:
                data.rotmass = data.mass
            self.atoms[name] = Atom(type=name, **data)

        for name1, atom1 in self.atoms.items():
            for name2, atom2 in self.atoms.items():

                try:
                    h = db.h_values[name1][name2]
                except KeyError:
                    try:
                        h = db.h_values[name2][name1]
                    except KeyError:
                        h = 1.

                self._lj_table_eps[name1][name2] = h * sqrt(atom1.epsilon * atom2.epsilon)
예제 #5
0
 def test_compare(self):
     self.assertEqual(Atom.compare(1, 1), 1)
     self.assertEqual(Atom.compare(None, 1), 1)
     self.assertEqual(Atom.compare(1, None), 1)
     self.assertEqual(Atom.compare(None, None), None)
     with self.assertRaises(ValueError):
         Atom.compare(1, 2)
예제 #6
0
    def __init__(self, filename=None):
        """
        Create a new MolDatabase object

        Args:
            filename: Name of molecule database file to open.
        """
        if filename is None:
            filename = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                    os.path.join("data", "mol-elba.json"))

        db = Parser(filename)
        try:
            self.version = db.version
        except KeyError:
            self.version = None
        self.molecules = {}

        for name, data in db.molecules.items():
            try:
                # Pop this because we want to add it separately
                atoms = data.pop("atoms")
            except KeyError:
                atoms = []

            self.molecules[name] = Molecule(**data)
            for atom in atoms:
                self.molecules[name].atoms[atom.name] = Atom(**atom)

        # Allow molecules to be based on templates
        # Allow nested templates, but ignore duplicates
        for mol in self.molecules.values():
            used_templates = set()
            while mol.templates:
                template = mol.templates.pop()
                if template not in used_templates:
                    mol.extend(self.molecules[template])
                    used_templates.add(template)
예제 #7
0
 def test_store_atom(self):
     atom = Atom(name="NamE", type="TypE")
     self.assertEqual(atom.name, "NamE")
     self.assertEqual(atom.type, "TypE")
예제 #8
0
 def test_create_atom(self):
     atom = Atom()