def load_restraints(filepath="restraints.json"): """Load restraints from a JSON file. Parameters ---------- filepath: os.PathLike The name of the JSON file to load. Returns ------- restraints: list List of :class:`paprika.restraints.DAT_restraint`. """ log.debug("Loading restraint information from JSON.") with open(os.path.join(filepath), "r") as f: json_data = f.read() restraint_json = json_data.split("\n") restraints = [] for restraint in restraint_json: if restraint == "": continue loaded = json.loads(restraint, object_hook=json_numpy_obj_hook) tmp = DAT_restraint() tmp.__dict__ = loaded properties = [ "mask1", "mask2", "mask3", "mask4", "topology", "instances", "custom_restraint_values", "auto_apr", "continuous_apr", "attach", "pull", "release", "amber_index", ] for class_property in properties: if f"_{class_property}" in tmp.__dict__.keys(): tmp.__dict__[class_property] = tmp.__dict__[ f"_{class_property}"] restraints.append(tmp) return restraints
def _parse_restraints(cls, restraint_dictionaries): """Parses the dictionary representations of a list of `paprika` restraint objects into a list of full restraint objects.""" from paprika.restraints import DAT_restraint restraints = [] for restraint_dictionary in restraint_dictionaries: restraint = DAT_restraint() restraint.__dict__ = restraint_dictionary properties = [ "mask1", "mask2", "mask3", "mask4", "topology", "instances", "custom_restraint_values", "auto_apr", "continuous_apr", "attach", "pull", "release", "amber_index", ] for class_property in properties: if f"_{class_property}" in restraint.__dict__.keys(): restraint.__dict__[class_property] = restraint.__dict__[ f"_{class_property}" ] restraints.append(restraint) return restraints
def load_restraints(filepath="restraints.json"): log.debug("Loading restraint information from JSON.") with open(os.path.join(filepath), "r") as f: json_data = f.read() restraint_json = json_data.split("\n") restraints = [] for restraint in restraint_json: if restraint == "": continue loaded = json.loads(restraint, object_hook=json_numpy_obj_hook) tmp = DAT_restraint() tmp.__dict__ = loaded try: log.debug("Setting topology from file name.") tmp.topology = pmd.load_file(loaded["topology"], structure=True) except IOError: log.debug( "Unable to set topology information after loading from JSON.") log.debug("Topology is set to the file name of the topology file.") tmp.topology = loaded["topology"] restraints.append(tmp) return restraints