def test_include_file(self): elba = Parser("data/mol-elba.json") self.assertTrue("version" in elba) self.assertTrue("lipids" in elba.version) molecules = Parser("data/mol-elba.json", section="molecules") self.assertTrue("DOPC" in molecules) self.assertTrue("DOPE" in molecules)
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)
def test_json_section(self): bonds = Parser("data/bonds.json", "bonds") self.assertTrue("length" in bonds) self.assertTrue("test" in bonds.length) self.assertEqual(["test", "100", "1.000"], bonds.length["test"].split())
def test_json_read(self): parser = Parser("data/bonds.json") self.assertTrue("bonds" in parser) self.assertTrue("length" in parser.bonds) self.assertTrue("test" in parser.bonds.length) self.assertEqual(["test", "100", "1.000"], parser.bonds.length["test"].split())
def __init__(self, filename=None): if filename is None: filename = os.path.join(os.path.dirname(os.path.dirname(__file__)), os.path.join("data", "bonds.json")) db = Parser(filename) Param = namedtuple("Param", ["style", "params"]) for tipe in ["length", "angle", "dihedral", "improper"]: setattr(self, tipe, dict()) for name, bond in db.bonds[tipe].items(): style, *params = bond.split() getattr(self, tipe)[name] = Param(style, " ".join(params))
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)
def test_missing_section(self): with self.assertRaises(KeyError): Parser("data/bonds.json", "potato")