コード例 #1
0
void read_ff_json(const char *json_file, struct atomgrp *ag)
{
	json_error_t json_file_error;
	json_t *base = json_load_file(json_file, 0, &json_file_error);

	if (!base) {
		fprintf(stderr,
			"error reading json file %s on line %d column %d: %s\n",
			json_file, json_file_error.line, json_file_error.column,
			json_file_error.text);
	}

	if (!json_is_object(base)) {
		fprintf(stderr, "json file not an object %s\n", json_file);
	}

	json_t *atoms, *bonds, *angles, *torsions, *impropers;
	atoms = json_object_get(base, "atoms");
	if (!json_is_array(atoms)) {
		fprintf(stderr, "json atoms are not an array %s\n", json_file);
	}
	size_t natoms = json_array_size(atoms);
	if (natoms != (size_t) ag->natoms) {
		fprintf(stderr,
			"json file has a different number of atoms %zd vs. %d : %s\n",
			natoms, ag->natoms, json_file);
	}

	ag->num_atom_types = 0;
	for (size_t i = 0; i < natoms; i++) {
		json_t *atom = json_array_get(atoms, i);
		if (!json_is_object(atom)) {
			fprintf(stderr,
				"Atom %zd not an object in json file %s\n", i,
				json_file);
		}
		json_t *ace_volume, *ftype_index, *ftype_name, *eps03;
		json_t *name, *radius03, *eps;
		json_t *charge, *radius, *element;

		ace_volume = json_object_get(atom, "ace_volume");
		if (!json_is_real(ace_volume)) {
			fprintf(stderr,
				"json ace volume is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].acevolume = json_real_value(ace_volume);

		ftype_index = json_object_get(atom, "ftype_index");
		if (!json_is_integer(ftype_index)) {
			fprintf(stderr,
				"json ftype index is not integer for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].atom_ftypen = json_integer_value(ftype_index);
		if (ag->atoms[i].atom_ftypen > ag->num_atom_types) {
			ag->num_atom_types = ag->atoms[i].atom_ftypen;
		}

		ftype_name = json_object_get(atom, "ftype_name");
		if (!json_is_string(ftype_name)) {
			fprintf(stderr,
				"json ftype name is not string for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].ftype_name = strdup(json_string_value(ftype_name));

		element = json_object_get(atom, "element");
		if (!json_is_string(element)) {
			fprintf(stderr,
				"json element name is not string for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].element = strdup(json_string_value(element));

		eps = json_object_get(atom, "eps");
		if (!json_is_real(eps)) {
			fprintf(stderr,
				"json eps is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].eps = sqrt(-json_real_value(eps));

		eps03 = json_object_get(atom, "eps03");
		if (!json_is_real(eps03)) {
			fprintf(stderr,
				"json eps03 is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].eps03 = sqrt(-json_real_value(eps03));

		radius = json_object_get(atom, "radius");
		if (!json_is_real(radius)) {
			fprintf(stderr,
				"json radius is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].rminh = json_real_value(radius);

		radius03 = json_object_get(atom, "radius03");
		if (!json_is_real(radius03)) {
			fprintf(stderr,
				"json radius03 is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].rminh03 = json_real_value(radius03);

		charge = json_object_get(atom, "charge");
		if (!json_is_real(radius03)) {
			fprintf(stderr,
				"json charge is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].chrg = json_real_value(charge);

		name = json_object_get(atom, "name");
		if (!json_is_string(name)) {
			fprintf(stderr,
				"json name is not string for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].name = strdup(json_string_value(name));

		ag->atoms[i].nbonds = 0;
		ag->atoms[i].nangs = 0;
		ag->atoms[i].ntors = 0;
		ag->atoms[i].nimps = 0;
		ag->atoms[i].fixed = 0;
	}

	bonds = json_object_get(base, "bonds");
	if (!json_is_array(bonds)) {
		fprintf(stderr, "json bonds are not an array %s\n", json_file);
	}
	size_t nbonds = json_array_size(bonds);
	ag->nbonds = nbonds;
	ag->bonds = _mol_calloc(nbonds, sizeof(struct atombond));
	for (size_t i = 0; i < nbonds; i++) {
		json_t *bond = json_array_get(bonds, i);
		if (!json_is_object(bond)) {
			fprintf(stderr,
				"Bond %zd not an object in json file %s\n", i,
				json_file);
		}
		json_t *length, *atom1, *atom2, *spring_constant, *sdf_type;

		atom1 = json_object_get(bond, "atom1");
		if (!json_is_integer(atom1)) {
			fprintf(stderr,
				"json atom1 is not integer for bond %zd in json_file %s\n",
				i, json_file);
		}
		int i1 = json_integer_value(atom1) - 1;
		ag->bonds[i].a0 = &(ag->atoms[i1]);
		(ag->atoms[i1].nbonds)++;

		atom2 = json_object_get(bond, "atom2");
		if (!json_is_integer(atom2)) {
			fprintf(stderr,
				"json atom2 is not integer for bond %zd in json_file %s\n",
				i, json_file);
		}
		int i2 = json_integer_value(atom2) - 1;
		ag->bonds[i].a1 = &(ag->atoms[i2]);
		(ag->atoms[i2].nbonds)++;

		length = json_object_get(bond, "length");
		if (!json_is_real(length)) {
			fprintf(stderr,
				"json length is not floating point for bond %zd in json_file %s\n",
				i, json_file);
		}
		ag->bonds[i].l0 = json_real_value(length);

		spring_constant = json_object_get(bond, "spring_constant");
		if (!json_is_real(spring_constant)) {
			fprintf(stderr,
				"json spring_constant is not floating point for bond %zd in json_file %s\n",
				i, json_file);
		}
		ag->bonds[i].k = json_real_value(spring_constant);

		sdf_type = json_object_get(bond, "sdf_type");
		if (!json_is_integer(sdf_type)) {
			fprintf(stderr,
				"json sdf_type is not integer for bond %zd in json_file %s\n",
				i, json_file);
		}
		ag->bonds[i].sdf_type = json_integer_value(sdf_type);
	}

	angles = json_object_get(base, "angles");
	if (!json_is_array(angles)) {
		fprintf(stderr, "json angles are not an array %s\n", json_file);
	}
	size_t nangles = json_array_size(angles);
	ag->nangs = nangles;
	ag->angs = _mol_calloc(nangles, sizeof(struct atomangle));
	for (size_t i = 0; i < nangles; i++) {
		json_t *angle = json_array_get(angles, i);
		if (!json_is_object(angle)) {
			fprintf(stderr,
				"Angle %zd not an object in json file %s\n", i,
				json_file);
		}
		json_t *theta, *atom1, *atom2, *atom3, *spring_constant;

		atom1 = json_object_get(angle, "atom1");
		if (!json_is_integer(atom1)) {
			fprintf(stderr,
				"json atom1 is not integer for angle %zd in json_file %s\n",
				i, json_file);
		}
		int i1 = json_integer_value(atom1) - 1;
		ag->angs[i].a0 = &(ag->atoms[i1]);
		(ag->atoms[i1].nangs)++;

		atom2 = json_object_get(angle, "atom2");
		if (!json_is_integer(atom2)) {
			fprintf(stderr,
				"json atom2 is not integer for angle %zd in json_file %s\n",
				i, json_file);
		}
		int i2 = json_integer_value(atom2) - 1;
		ag->angs[i].a1 = &(ag->atoms[i2]);
		(ag->atoms[i2].nangs)++;

		atom3 = json_object_get(angle, "atom3");
		if (!json_is_integer(atom3)) {
			fprintf(stderr,
				"json atom3 is not integer for angle %zd in json_file %s\n",
				i, json_file);
		}
		int i3 = json_integer_value(atom3) - 1;
		ag->angs[i].a2 = &(ag->atoms[i3]);
		(ag->atoms[i3].nangs)++;

		theta = json_object_get(angle, "theta");
		if (!json_is_real(theta)) {
			fprintf(stderr,
				"json theta is not floating point for angle %zd in json_file %s\n",
				i, json_file);
		}
		ag->angs[i].th0 = json_real_value(theta);

		spring_constant = json_object_get(angle, "spring_constant");
		if (!json_is_real(spring_constant)) {
			fprintf(stderr,
				"json spring_constant is not floating point for angle %zd in json_file %s\n",
				i, json_file);
		}
		ag->angs[i].k = json_real_value(spring_constant);
	}

	torsions = json_object_get(base, "torsions");
	if (!json_is_array(torsions)) {
		fprintf(stderr, "json torsions are not an array %s\n",
			json_file);
	}
	size_t ntorsions = json_array_size(torsions);
	ag->ntors = ntorsions;
	ag->tors = _mol_calloc(ntorsions, sizeof(struct atomtorsion));
	for (size_t i = 0; i < ntorsions; i++) {
		json_t *torsion = json_array_get(torsions, i);
		if (!json_is_object(torsion)) {
			fprintf(stderr,
				"Torsion %zd not an object in json file %s\n",
				i, json_file);
		}
		json_t *atom1, *atom2, *atom3, *atom4, *minima, *delta_constant,
		    *spring_constant;

		atom1 = json_object_get(torsion, "atom1");
		if (!json_is_integer(atom1)) {
			fprintf(stderr,
				"json atom1 is not integer for torsion %zd in json_file %s\n",
				i, json_file);
		}
		int i1 = json_integer_value(atom1) - 1;
		ag->tors[i].a0 = &(ag->atoms[i1]);
		(ag->atoms[i1].ntors)++;

		atom2 = json_object_get(torsion, "atom2");
		if (!json_is_integer(atom2)) {
			fprintf(stderr,
				"json atom2 is not integer for torsion %zd in json_file %s\n",
				i, json_file);
		}
		int i2 = json_integer_value(atom2) - 1;
		ag->tors[i].a1 = &(ag->atoms[i2]);
		(ag->atoms[i2].ntors)++;

		atom3 = json_object_get(torsion, "atom3");
		if (!json_is_integer(atom3)) {
			fprintf(stderr,
				"json atom3 is not integer for torsion %zd in json_file %s\n",
				i, json_file);
		}
		int i3 = json_integer_value(atom3) - 1;
		ag->tors[i].a2 = &(ag->atoms[i3]);
		(ag->atoms[i3].ntors)++;

		atom4 = json_object_get(torsion, "atom4");
		if (!json_is_integer(atom4)) {
			fprintf(stderr,
				"json atom4 is not integer for torsion %zd in json_file %s\n",
				i, json_file);
		}
		int i4 = json_integer_value(atom4) - 1;
		ag->tors[i].a3 = &(ag->atoms[i4]);
		(ag->atoms[i4].ntors)++;

		minima = json_object_get(torsion, "minima");
		if (!json_is_integer(minima)) {
			fprintf(stderr,
				"json minima is not integer for torsion %zd in json_file %s\n",
				i, json_file);
		}
		ag->tors[i].n = json_integer_value(minima);

		delta_constant = json_object_get(torsion, "delta_constant");
		if (!json_is_real(delta_constant)) {
			fprintf(stderr,
				"json delta_constant is not floating point for torsion %zd in json_file %s\n",
				i, json_file);
		}
		ag->tors[i].d = json_real_value(delta_constant);

		spring_constant = json_object_get(torsion, "spring_constant");
		if (!json_is_real(spring_constant)) {
			fprintf(stderr,
				"json spring_constant is not floating point for torsion %zd in json_file %s\n",
				i, json_file);
		}
		ag->tors[i].k = json_real_value(spring_constant);
	}

	impropers = json_object_get(base, "impropers");
	if (!json_is_array(impropers)) {
		fprintf(stderr, "json impropers are not an array %s\n",
			json_file);
	}
	size_t nimpropers = json_array_size(impropers);
	ag->nimps = nimpropers;
	ag->imps = _mol_calloc(nimpropers, sizeof(struct atomimproper));
	for (size_t i = 0; i < nimpropers; i++) {
		json_t *improper = json_array_get(impropers, i);
		if (!json_is_object(improper)) {
			fprintf(stderr,
				"Improper %zd not an object in json file %s\n",
				i, json_file);
		}
		json_t *atom1, *atom2, *atom3, *atom4, *phi, *spring_constant;

		atom1 = json_object_get(improper, "atom1");
		if (!json_is_integer(atom1)) {
			fprintf(stderr,
				"json atom1 is not integer for improper %zd in json_file %s\n",
				i, json_file);
		}
		int i1 = json_integer_value(atom1) - 1;
		ag->imps[i].a0 = &(ag->atoms[i1]);
		(ag->atoms[i1].nimps)++;

		atom2 = json_object_get(improper, "atom2");
		if (!json_is_integer(atom2)) {
			fprintf(stderr,
				"json atom2 is not integer for improper %zd in json_file %s\n",
				i, json_file);
		}
		int i2 = json_integer_value(atom2) - 1;
		ag->imps[i].a1 = &(ag->atoms[i2]);
		(ag->atoms[i2].nimps)++;

		atom3 = json_object_get(improper, "atom3");
		if (!json_is_integer(atom3)) {
			fprintf(stderr,
				"json atom3 is not integer for improper %zd in json_file %s\n",
				i, json_file);
		}
		int i3 = json_integer_value(atom3) - 1;
		ag->imps[i].a2 = &(ag->atoms[i3]);
		(ag->atoms[i3].nimps)++;

		atom4 = json_object_get(improper, "atom4");
		if (!json_is_integer(atom4)) {
			fprintf(stderr,
				"json atom4 is not integer for improper %zd in json_file %s\n",
				i, json_file);
		}
		int i4 = json_integer_value(atom4) - 1;
		ag->imps[i].a3 = &(ag->atoms[i4]);
		(ag->atoms[i4].nimps)++;

		phi = json_object_get(improper, "phi");
		if (!json_is_real(phi)) {
			fprintf(stderr,
				"json phi is not floating point for improper %zd in json_file %s\n",
				i, json_file);
		}
		ag->imps[i].psi0 = json_real_value(phi);

		spring_constant = json_object_get(improper, "spring_constant");
		if (!json_is_real(spring_constant)) {
			fprintf(stderr,
				"json spring_constant is not floating point for improper %zd in json_file %s\n",
				i, json_file);
		}
		ag->imps[i].k = json_real_value(spring_constant);
	}

	json_decref(base);

//allocate atom arrays of pointers to parameters
	for (size_t i = 0; i < natoms; i++) {
		int i1 = ag->atoms[i].nbonds;
		ag->atoms[i].bonds = _mol_calloc(i1, sizeof(struct atombond *));
		ag->atoms[i].nbonds = 0;
		i1 = ag->atoms[i].nangs;
		ag->atoms[i].angs = _mol_calloc(i1, sizeof(struct atomangle *));
		ag->atoms[i].nangs = 0;
		i1 = ag->atoms[i].ntors;
		ag->atoms[i].tors =
		    _mol_calloc(i1, sizeof(struct atomtorsion *));
		ag->atoms[i].ntors = 0;
		i1 = ag->atoms[i].nimps;
		ag->atoms[i].imps =
		    _mol_calloc(i1, sizeof(struct atomimproper *));
		ag->atoms[i].nimps = 0;
	}
	struct atom *atm;
//fill bonds
	for (int i = 0; i < ag->nbonds; i++) {
		atm = ag->bonds[i].a0;
		atm->bonds[(atm->nbonds)++] = &(ag->bonds[i]);
		atm = ag->bonds[i].a1;
		atm->bonds[(atm->nbonds)++] = &(ag->bonds[i]);
	}
//fill angles
	for (int i = 0; i < ag->nangs; i++) {
		atm = ag->angs[i].a0;
		atm->angs[(atm->nangs)++] = &(ag->angs[i]);
		atm = ag->angs[i].a1;
		atm->angs[(atm->nangs)++] = &(ag->angs[i]);
		atm = ag->angs[i].a2;
		atm->angs[(atm->nangs)++] = &(ag->angs[i]);
	}
//fill torsions
	for (int i = 0; i < ag->ntors; i++) {
		atm = ag->tors[i].a0;
		atm->tors[(atm->ntors)++] = &(ag->tors[i]);
		atm = ag->tors[i].a1;
		atm->tors[(atm->ntors)++] = &(ag->tors[i]);
		atm = ag->tors[i].a2;
		atm->tors[(atm->ntors)++] = &(ag->tors[i]);
		atm = ag->tors[i].a3;
		atm->tors[(atm->ntors)++] = &(ag->tors[i]);
	}
//fill impropers
	for (int i = 0; i < ag->nimps; i++) {
		atm = ag->imps[i].a0;
		atm->imps[(atm->nimps)++] = &(ag->imps[i]);
		atm = ag->imps[i].a1;
		atm->imps[(atm->nimps)++] = &(ag->imps[i]);
		atm = ag->imps[i].a2;
		atm->imps[(atm->nimps)++] = &(ag->imps[i]);
		atm = ag->imps[i].a3;
		atm->imps[(atm->nimps)++] = &(ag->imps[i]);
	}
//atom indices in the group
	fill_ingrp(ag);

	ag->is_psf_read = true;

	// copy vals from deprecated to new data structures
	int atomsi;
	for (atomsi = 0; atomsi < ag->natoms; atomsi++) {
		_mol_atom_create_bond_indices(&ag->atoms[atomsi],
					      ag->atoms[atomsi].nbonds);
	}
	_mol_atom_group_copy_from_deprecated(ag);
}
コード例 #2
0
struct atomgrp *join_rec_lig_ff(struct atomgrp *rec, struct atomgrp *lig)
{
	int i;
	int j;
	struct atomgrp *ag =
	    (struct atomgrp *)_mol_calloc(1, sizeof(struct atomgrp));

	//sum counts
	ag->natoms = rec->natoms + lig->natoms;
	ag->nbonds = rec->nbonds + lig->nbonds;
	ag->nangs = rec->nangs + lig->nangs;
	ag->ntors = rec->ntors + lig->ntors;
	ag->nimps = rec->nimps + lig->nimps;
	ag->num_atom_types = rec->num_atom_types + lig->num_atom_types;
	//don't think we need actives yet
	//ag->nactives = rec->nactives + lig->nactives;
	//ag->nbact    = rec->nbact   + lig->nbact;
	//ag->nangact  = rec->nangact + lig->nangact;
	//ag->ntoract  = rec->ntoract + lig->ntoract;
	//ag->nimpact  = rec->nimpact + lig->nimpact;

	//allocate first level
	ag->atoms =
	    (struct atom *)_mol_malloc(sizeof(struct atom) * ag->natoms);
	ag->bonds =
	    (struct atombond *)_mol_malloc(sizeof(struct atombond) *
					   ag->nbonds);
	ag->angs =
	    (struct atomangle *)_mol_malloc(sizeof(struct atomangle) *
					    ag->nangs);
	ag->tors =
	    (struct atomtorsion *)_mol_malloc(sizeof(struct atomtorsion) *
					      ag->ntors);
	ag->imps =
	    (struct atomimproper *)_mol_malloc(sizeof(struct atomimproper) *
					       ag->nimps);

	//copy rec items
	memcpy(ag->atoms, rec->atoms, sizeof(struct atom) * rec->natoms);
	memcpy(ag->bonds, rec->bonds, sizeof(struct atombond) * rec->nbonds);
	memcpy(ag->angs, rec->angs, sizeof(struct atomangle) * rec->nangs);
	memcpy(ag->tors, rec->tors, sizeof(struct atomtorsion) * rec->ntors);
	memcpy(ag->imps, rec->imps, sizeof(struct atomimproper) * rec->nimps);

	//point to correct atoms
	for (i = 0; i < rec->nbonds; i++) {
		ptrdiff_t a0_offset = ag->bonds[i].a0 - rec->atoms;
		ptrdiff_t a1_offset = ag->bonds[i].a1 - rec->atoms;
		ag->bonds[i].a0 = ag->atoms + a0_offset;
		ag->bonds[i].a1 = ag->atoms + a1_offset;
	}
	for (i = 0; i < rec->nangs; i++) {
		ptrdiff_t a0_offset = ag->angs[i].a0 - rec->atoms;
		ptrdiff_t a1_offset = ag->angs[i].a1 - rec->atoms;
		ptrdiff_t a2_offset = ag->angs[i].a2 - rec->atoms;
		ag->angs[i].a0 = ag->atoms + a0_offset;
		ag->angs[i].a1 = ag->atoms + a1_offset;
		ag->angs[i].a2 = ag->atoms + a2_offset;
	}
	for (i = 0; i < rec->ntors; i++) {
		ptrdiff_t a0_offset = ag->tors[i].a0 - rec->atoms;
		ptrdiff_t a1_offset = ag->tors[i].a1 - rec->atoms;
		ptrdiff_t a2_offset = ag->tors[i].a2 - rec->atoms;
		ptrdiff_t a3_offset = ag->tors[i].a3 - rec->atoms;
		ag->tors[i].a0 = ag->atoms + a0_offset;
		ag->tors[i].a1 = ag->atoms + a1_offset;
		ag->tors[i].a2 = ag->atoms + a2_offset;
		ag->tors[i].a3 = ag->atoms + a3_offset;
	}
	for (i = 0; i < rec->nimps; i++) {
		ptrdiff_t a0_offset = ag->imps[i].a0 - rec->atoms;
		ptrdiff_t a1_offset = ag->imps[i].a1 - rec->atoms;
		ptrdiff_t a2_offset = ag->imps[i].a2 - rec->atoms;
		ptrdiff_t a3_offset = ag->imps[i].a3 - rec->atoms;
		ag->imps[i].a0 = ag->atoms + a0_offset;
		ag->imps[i].a1 = ag->atoms + a1_offset;
		ag->imps[i].a2 = ag->atoms + a2_offset;
		ag->imps[i].a3 = ag->atoms + a3_offset;
	}

	//point to atoms to correct bonds, angs, tors, imps
	for (i = 0; i < rec->natoms; i++) {
		ag->atoms[i].name = strdup(rec->atoms[i].name);
		if (rec->atoms[i].residue_name != NULL) {
			ag->atoms[i].residue_name = strdup(rec->atoms[i].residue_name);
		}
		ag->atoms[i].ftype_name = strdup(rec->atoms[i].ftype_name);

		ag->atoms[i].bonds =
		    _mol_malloc(rec->atoms[i].nbonds *
				sizeof(struct atombond *));
		memcpy(ag->atoms[i].bonds, rec->atoms[i].bonds,
		       sizeof(struct atombond *) * rec->atoms[i].nbonds);
		for (j = 0; j < ag->atoms[i].nbonds; j++) {
			ptrdiff_t bond_offset =
			    ag->atoms[i].bonds[j] - rec->bonds;
			ag->atoms[i].bonds[j] = ag->bonds + bond_offset;
		}
		ag->atoms[i].angs =
		    _mol_malloc(rec->atoms[i].nangs *
				sizeof(struct atomangle *));
		memcpy(ag->atoms[i].angs, rec->atoms[i].angs,
		       sizeof(struct atomangle *) * rec->atoms[i].nangs);
		for (j = 0; j < ag->atoms[i].nangs; j++) {
			ptrdiff_t ang_offset = ag->atoms[i].angs[j] - rec->angs;
			ag->atoms[i].angs[j] = ag->angs + ang_offset;
		}
		ag->atoms[i].tors =
		    _mol_malloc(rec->atoms[i].ntors *
				sizeof(struct atomtorsion *));
		memcpy(ag->atoms[i].tors, rec->atoms[i].tors,
		       sizeof(struct atomtorsion *) * rec->atoms[i].ntors);
		for (j = 0; j < ag->atoms[i].ntors; j++) {
			ptrdiff_t tor_offset = ag->atoms[i].tors[j] - rec->tors;
			ag->atoms[i].tors[j] = ag->tors + tor_offset;
		}
		ag->atoms[i].imps =
		    _mol_malloc(rec->atoms[i].nimps *
				sizeof(struct atomimproper *));
		memcpy(ag->atoms[i].imps, rec->atoms[i].imps,
		       sizeof(struct atomimproper *) * rec->atoms[i].nimps);
		for (j = 0; j < ag->atoms[i].nimps; j++) {
			ptrdiff_t imp_offset = ag->atoms[i].imps[j] - rec->imps;
			ag->atoms[i].imps[j] = ag->imps + imp_offset;
		}
	}

	//copy lig items
	memcpy(ag->atoms + rec->natoms, lig->atoms,
	       sizeof(struct atom) * lig->natoms);
	memcpy(ag->bonds + rec->nbonds, lig->bonds,
	       sizeof(struct atombond) * lig->nbonds);
	memcpy(ag->angs + rec->nangs, lig->angs,
	       sizeof(struct atomangle) * lig->nangs);
	memcpy(ag->tors + rec->ntors, lig->tors,
	       sizeof(struct atomtorsion) * lig->ntors);
	memcpy(ag->imps + rec->nimps, lig->imps,
	       sizeof(struct atomimproper) * lig->nimps);

	//point to correct atoms
	struct atom *newlig_atoms = ag->atoms + rec->natoms;
	for (i = rec->nbonds; i < ag->nbonds; i++) {
		ptrdiff_t a0_offset = ag->bonds[i].a0 - lig->atoms;
		ptrdiff_t a1_offset = ag->bonds[i].a1 - lig->atoms;
		ag->bonds[i].a0 = newlig_atoms + a0_offset;
		ag->bonds[i].a1 = newlig_atoms + a1_offset;
		ag->bonds[i].ai += rec->natoms;
		ag->bonds[i].aj += rec->natoms;
	}
	for (i = rec->nangs; i < ag->nangs; i++) {
		ptrdiff_t a0_offset = ag->angs[i].a0 - lig->atoms;
		ptrdiff_t a1_offset = ag->angs[i].a1 - lig->atoms;
		ptrdiff_t a2_offset = ag->angs[i].a2 - lig->atoms;
		ag->angs[i].a0 = newlig_atoms + a0_offset;
		ag->angs[i].a1 = newlig_atoms + a1_offset;
		ag->angs[i].a2 = newlig_atoms + a2_offset;
	}
	for (i = rec->ntors; i < ag->ntors; i++) {
		ptrdiff_t a0_offset = ag->tors[i].a0 - lig->atoms;
		ptrdiff_t a1_offset = ag->tors[i].a1 - lig->atoms;
		ptrdiff_t a2_offset = ag->tors[i].a2 - lig->atoms;
		ptrdiff_t a3_offset = ag->tors[i].a3 - lig->atoms;
		ag->tors[i].a0 = newlig_atoms + a0_offset;
		ag->tors[i].a1 = newlig_atoms + a1_offset;
		ag->tors[i].a2 = newlig_atoms + a2_offset;
		ag->tors[i].a3 = newlig_atoms + a3_offset;
	}
	for (i = rec->nimps; i < ag->nimps; i++) {
		ptrdiff_t a0_offset = ag->imps[i].a0 - lig->atoms;
		ptrdiff_t a1_offset = ag->imps[i].a1 - lig->atoms;
		ptrdiff_t a2_offset = ag->imps[i].a2 - lig->atoms;
		ptrdiff_t a3_offset = ag->imps[i].a3 - lig->atoms;
		ag->imps[i].a0 = newlig_atoms + a0_offset;
		ag->imps[i].a1 = newlig_atoms + a1_offset;
		ag->imps[i].a2 = newlig_atoms + a2_offset;
		ag->imps[i].a3 = newlig_atoms + a3_offset;
	}

	int max_rec_res_seq = rec->atoms[rec->natoms-1].comb_res_seq;

	//point to atoms to correct bonds, angs, tors, imps
	struct atombond *newlig_bonds = ag->bonds + rec->nbonds;
	struct atomangle *newlig_angs = ag->angs + rec->nangs;
	struct atomtorsion *newlig_tors = ag->tors + rec->ntors;
	struct atomimproper *newlig_imps = ag->imps + rec->nimps;
	for (i = rec->natoms; i < ag->natoms; i++) {
//              struct atom local_atom = ag->atoms[i];
		ag->atoms[i].comb_res_seq += 100 + max_rec_res_seq;
		ag->atoms[i].atom_ftypen += rec->num_atom_types;
		ag->atoms[i].name = strdup(lig->atoms[i - (rec->natoms)].name);
		if (lig->atoms[i - (rec->natoms)].residue_name != NULL) {
			ag->atoms[i].residue_name =
			    strdup(lig->atoms[i - (rec->natoms)].residue_name);
		}
		ag->atoms[i].ftype_name =
		    strdup(lig->atoms[i - (rec->natoms)].ftype_name);

		ag->atoms[i].bonds =
		    _mol_malloc(lig->atoms[i - (rec->natoms)].nbonds *
				sizeof(struct atombond *));
		memcpy(ag->atoms[i].bonds, lig->atoms[i - (rec->natoms)].bonds,
		       sizeof(struct atombond *) * lig->atoms[i -
							      (rec->natoms)].
		       nbonds);
		for (j = 0; j < ag->atoms[i].nbonds; j++) {
			ptrdiff_t bond_offset =
			    ag->atoms[i].bonds[j] - lig->bonds;
			ag->atoms[i].bonds[j] = newlig_bonds + bond_offset;
		}
		ag->atoms[i].angs =
		    _mol_malloc(lig->atoms[i - (rec->natoms)].nangs *
				sizeof(struct atomangle *));
		memcpy(ag->atoms[i].angs, lig->atoms[i - (rec->natoms)].angs,
		       sizeof(struct atomangle *) * lig->atoms[i -
							       (rec->natoms)].
		       nangs);
		for (j = 0; j < ag->atoms[i].nangs; j++) {
			ptrdiff_t ang_offset = ag->atoms[i].angs[j] - lig->angs;
			ag->atoms[i].angs[j] = newlig_angs + ang_offset;
		}
		ag->atoms[i].tors =
		    _mol_malloc(lig->atoms[i - (rec->natoms)].ntors *
				sizeof(struct atomtorsion *));
		memcpy(ag->atoms[i].tors, lig->atoms[i - (rec->natoms)].tors,
		       sizeof(struct atomtorsion *) * lig->atoms[i -
								 (rec->natoms)].
		       ntors);
		for (j = 0; j < ag->atoms[i].ntors; j++) {
			ptrdiff_t tor_offset = ag->atoms[i].tors[j] - lig->tors;
			ag->atoms[i].tors[j] = newlig_tors + tor_offset;
		}
		ag->atoms[i].imps =
		    _mol_malloc(lig->atoms[i - (rec->natoms)].nimps *
				sizeof(struct atomimproper *));
		memcpy(ag->atoms[i].imps, lig->atoms[i - (rec->natoms)].imps,
		       sizeof(struct atomimproper *) * lig->atoms[i -
								  (rec->
								   natoms)].
		       nimps);
		for (j = 0; j < ag->atoms[i].nimps; j++) {
			ptrdiff_t imp_offset = ag->atoms[i].imps[j] - lig->imps;
			ag->atoms[i].imps[j] = newlig_imps + imp_offset;
		}
	}

	//copy into ryan's structure
//      _mol_atom_group_copy_from_deprecated(ag);

	fill_ingrp(ag);

	return ag;
}
コード例 #3
0
struct atomgrp *read_json_ag(const char *json_file)
{
	struct atomgrp *ag =
	    (struct atomgrp *)_mol_calloc(1, sizeof(struct atomgrp));
	json_error_t json_file_error;
	json_t *base = json_load_file(json_file, 0, &json_file_error);

	if (!base) {
		fprintf(stderr,
			"error reading json file %s on line %d column %d: %s\n",
			json_file, json_file_error.line, json_file_error.column,
			json_file_error.text);
	}

	if (!json_is_object(base)) {
		fprintf(stderr, "json file not an object %s\n", json_file);
	}

	json_t *atoms, *bonds, *angles, *torsions, *impropers;
	atoms = json_object_get(base, "atoms");
	if (!json_is_array(atoms)) {
		fprintf(stderr, "json atoms are not an array %s\n", json_file);
	}
	size_t natoms = json_array_size(atoms);
	ag->natoms = natoms;
	ag->atoms = (struct atom *)_mol_calloc(ag->natoms, sizeof(struct atom));

	ag->num_atom_types = 0;

	char *prev_segment = _mol_calloc(1, sizeof(char));
	char *prev_residue = _mol_calloc(1, sizeof(char));
	int prev_residue_seq = -107;
	ag->nres = 0;
	int alloc_res = 250;
	ag->iares = _mol_malloc(alloc_res*sizeof(int));
	for (size_t i = 0; i < natoms; i++) {
		json_t *atom = json_array_get(atoms, i);
		if (!json_is_object(atom)) {
			fprintf(stderr,
				"Atom %zd not an object in json file %s\n", i,
				json_file);
		}
		json_t *ace_volume, *ftype_index, *ftype_name, *eps03;
		json_t *name, *radius03, *eps, *acp_type, *residue_name;
		json_t *charge, *radius, *element;
		json_t *x, *y, *z;
		json_t *yeti_type, *sybyl_type;
		json_t *backbone, *hb_acceptor, *hb_donor, *hb_weight;
		json_t *segment, *residue;


		segment = json_object_get(atom, "segment");
		residue = json_object_get(atom, "residue");
		if ((segment != NULL) && (residue != NULL)) {
			if (!json_is_string(segment)) {
				fprintf(stderr,
					"json segment is not string for atom %zd in json_file %s\n",
					i, json_file);
			}
			if (!json_is_string(residue)) {
				fprintf(stderr,
					"json residue is not string for atom %zd in json_file %s\n",
					i, json_file);
			}

			const char *cur_segment = json_string_value(segment);
			const char *cur_residue = json_string_value(residue);

			if (strcmp(cur_segment, prev_segment) != 0) {
				prev_residue_seq += 100;
				free(prev_segment);
				prev_segment = strdup(cur_segment);
			}
			if (strcmp(cur_residue, prev_residue) != 0) {
				int cur_residue_int = atoi(cur_residue);
				int prev_residue_int = atoi(prev_residue);
				if ((cur_residue_int - prev_residue_int) > 1) {
					prev_residue_seq +=
					    (cur_residue_int -
					     prev_residue_int);
				} else {
					prev_residue_seq += 1;
				}
				free(prev_residue);
				prev_residue = strdup(cur_residue);

				if (ag->nres +1 == alloc_res) {
					alloc_res *= 2;
					ag->iares = _mol_realloc(ag->iares, alloc_res * i);
				}
				ag->iares[ag->nres] = i;
				ag->nres++;
			}


			ag->atoms[i].comb_res_seq = prev_residue_seq;
		} else {
			ag->atoms[i].comb_res_seq = prev_residue_seq;
		}

		ace_volume = json_object_get(atom, "ace_volume");
		if (!json_is_real(ace_volume)) {
			fprintf(stderr,
				"json ace volume is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].acevolume = json_real_value(ace_volume);

		ftype_index = json_object_get(atom, "ftype_index");
		if (!json_is_integer(ftype_index)) {
			fprintf(stderr,
				"json ftype index is not integer for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].atom_ftypen = json_integer_value(ftype_index);
		if (ag->atoms[i].atom_ftypen > ag->num_atom_types) {
			ag->num_atom_types = ag->atoms[i].atom_ftypen;
		}

		ftype_name = json_object_get(atom, "ftype_name");
		if (!json_is_string(ftype_name)) {
			fprintf(stderr,
				"json ftype name is not string for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].ftype_name = strdup(json_string_value(ftype_name));

		element = json_object_get(atom, "element");
		if (!json_is_string(element)) {
			fprintf(stderr,
				"json element name is not string for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].element = strdup(json_string_value(element));

		eps = json_object_get(atom, "eps");
		if (!json_is_real(eps)) {
			fprintf(stderr,
				"json eps is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].eps = sqrt(-json_real_value(eps));

		eps03 = json_object_get(atom, "eps03");
		if (!json_is_real(eps03)) {
			fprintf(stderr,
				"json eps03 is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].eps03 = sqrt(-json_real_value(eps03));

		radius = json_object_get(atom, "radius");
		if (!json_is_real(radius)) {
			fprintf(stderr,
				"json radius is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].rminh = json_real_value(radius);

		radius03 = json_object_get(atom, "radius03");
		if (!json_is_real(radius03)) {
			fprintf(stderr,
				"json radius03 is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].rminh03 = json_real_value(radius03);

		charge = json_object_get(atom, "charge");
		if (!json_is_real(radius03)) {
			fprintf(stderr,
				"json charge is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].chrg = json_real_value(charge);

		name = json_object_get(atom, "name");
		if (!json_is_string(name)) {
			fprintf(stderr,
				"json name is not string for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].name = strdup(json_string_value(name));

		residue_name = json_object_get(atom, "residue_name");
		if (residue_name != NULL) {
			if (!json_is_string(residue_name)) {
				fprintf(stderr,
					"json residue_name is not string for atom %zd in json_file %s\n",
					i, json_file);
			}
			ag->atoms[i].residue_name =
			    strdup(json_string_value(residue_name));
		} else {
			ag->atoms[i].residue_name = NULL;
		}

		x = json_object_get(atom, "x");
		if (!json_is_real(x)) {
			fprintf(stderr,
				"json coordinate x is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].X = json_real_value(x);

		y = json_object_get(atom, "y");
		if (!json_is_real(y)) {
			fprintf(stderr,
				"json coordinate y is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].Y = json_real_value(y);

		z = json_object_get(atom, "z");
		if (!json_is_real(z)) {
			fprintf(stderr,
				"json coordinate z is not floating point for atom %zd in json_file %s\n",
				i, json_file);
		}
		ag->atoms[i].Z = json_real_value(z);

		acp_type = json_object_get(atom, "acp_type");
		if (acp_type != NULL) {
			if (!json_is_integer(acp_type)) {
				fprintf(stderr,
					"json acp_type index is not integer for atom %zd in json_file %s\n",
					i, json_file);
			}
			ag->atoms[i].acp_type = json_integer_value(acp_type);
		} else {
			ag->atoms[i].acp_type = -1;
		}

		yeti_type = json_object_get(atom, "yeti_type");
		if (yeti_type != NULL) {
			const char *yeti_type_string;
			if (!json_is_string(yeti_type)) {
				fprintf(stderr,
					"json yeti_type is not string for atom %zd in json_file %s\n",
					i, json_file);
			}
			yeti_type_string = json_string_value(yeti_type);
			if (strcmp("carbonyl", yeti_type_string) == 0) {
				ag->atoms[i].yeti_type = MOL_YETI_CARBONYL;
			} else if (strcmp("hydroxyl", yeti_type_string) == 0) {
				ag->atoms[i].yeti_type = MOL_YETI_HYDROXYL;
			} else if (strcmp("sulfonamide", yeti_type_string) == 0) {
				ag->atoms[i].yeti_type = MOL_YETI_SULFONAMIDE;
			} else if (strcmp("N5_aromatic", yeti_type_string) == 0) {
				ag->atoms[i].yeti_type = MOL_YETI_N5_AROMATIC;
			} else if (strcmp("N6_aromatic", yeti_type_string) == 0) {
				ag->atoms[i].yeti_type = MOL_YETI_N6_AROMATIC;
			} else {
				fprintf(stderr,
					"unknown json yeti_type %s for atom %zd in json_file %s\n",
					yeti_type_string, i, json_file);
				ag->atoms[i].yeti_type = MOL_YETI_NONE;
			}
		} else {
			ag->atoms[i].yeti_type = MOL_YETI_NONE;
		}

		sybyl_type = json_object_get(atom, "sybyl_type");
		if (sybyl_type != NULL) {
			const char *sybyl_type_string;
			if (!json_is_string(sybyl_type)) {
				fprintf(stderr,
					"json sybyl_type is not string for atom %zd in json_file %s\n",
					i, json_file);
			}
			sybyl_type_string = json_string_value(sybyl_type);
			ag->atoms[i].hybridization =
			    mol_hydridization_from_sybyl(sybyl_type_string);
		} else {
			ag->atoms[i].hybridization = UNKNOWN_HYBRID;
		}

		backbone = json_object_get(atom, "backbone");
		if (backbone != NULL) {
			if (!json_is_boolean(backbone)) {
				fprintf(stderr,
					"json backbone is not boolean for atom %zd in json_file %s\n",
					i, json_file);
			}
			ag->atoms[i].backbone = json_is_true(backbone);
		} else {
			ag->atoms[i].backbone = false;
		}

		ag->atoms[i].hprop = 0;
		hb_acceptor = json_object_get(atom, "hb_acceptor");
		if (hb_acceptor != NULL) {
			if (!json_is_boolean(hb_acceptor)) {
				fprintf(stderr,
					"json hb_acceptor is not boolean for atom %zd in json_file %s\n",
					i, json_file);
			}
			if (json_is_true(hb_acceptor)) {
				ag->atoms[i].hprop |= HBOND_ACCEPTOR;
			}
		}
		hb_donor = json_object_get(atom, "hb_donor");
		if (hb_donor != NULL) {
			if (!json_is_boolean(hb_donor)) {
				fprintf(stderr,
					"json hb_donor is not boolean for atom %zd in json_file %s\n",
					i, json_file);
			}
			if (json_is_true(hb_donor)) {
				ag->atoms[i].hprop |= DONATABLE_HYDROGEN;
			}
		}
		ag->atoms[i].hbond_weight = 1.0;
		hb_weight = json_object_get(atom, "hb_weight");
		if (hb_weight != NULL) {
			if (!json_is_real(hb_weight)) {
				fprintf(stderr,
					"json hb_weight is not floating point for atom %zd in json_file %s\n",
					i, json_file);
			}
			ag->atoms[i].hbond_weight = json_real_value(hb_weight);
		}

		ag->atoms[i].nbonds = 0;
		ag->atoms[i].nangs = 0;
		ag->atoms[i].ntors = 0;
		ag->atoms[i].nimps = 0;
		ag->atoms[i].fixed = 0;
		ag->atoms[i].sa = -1;
		ag->atoms[i].base = -1;
		ag->atoms[i].base2 = -1;
	}
	ag->iares[ag->nres] = ag->natoms;
	ag->iares = _mol_realloc(ag->iares, (ag->nres+1) * sizeof(int));
	free(prev_segment);
	free(prev_residue);

	bonds = json_object_get(base, "bonds");
	if (!json_is_array(bonds)) {
		fprintf(stderr, "json bonds are not an array %s\n", json_file);
	}
	size_t nbonds = json_array_size(bonds);
	ag->nbonds = nbonds;
	ag->bonds = _mol_calloc(nbonds, sizeof(struct atombond));
	for (size_t i = 0; i < nbonds; i++) {
		json_t *bond = json_array_get(bonds, i);
		if (!json_is_object(bond)) {
			fprintf(stderr,
				"Bond %zd not an object in json file %s\n", i,
				json_file);
		}
		json_t *length, *atom1, *atom2, *spring_constant, *sdf_type;

		atom1 = json_object_get(bond, "atom1");
		if (!json_is_integer(atom1)) {
			fprintf(stderr,
				"json atom1 is not integer for bond %zd in json_file %s\n",
				i, json_file);
		}
		int i1 = json_integer_value(atom1) - 1;
		ag->bonds[i].a0 = &(ag->atoms[i1]);
		(ag->atoms[i1].nbonds)++;

		atom2 = json_object_get(bond, "atom2");
		if (!json_is_integer(atom2)) {
			fprintf(stderr,
				"json atom2 is not integer for bond %zd in json_file %s\n",
				i, json_file);
		}
		int i2 = json_integer_value(atom2) - 1;
		ag->bonds[i].a1 = &(ag->atoms[i2]);
		(ag->atoms[i2].nbonds)++;

		length = json_object_get(bond, "length");
		if (!json_is_real(length)) {
			fprintf(stderr,
				"json length is not floating point for bond %zd in json_file %s\n",
				i, json_file);
		}
		ag->bonds[i].l0 = json_real_value(length);

		spring_constant = json_object_get(bond, "spring_constant");
		if (!json_is_real(spring_constant)) {
			fprintf(stderr,
				"json spring_constant is not floating point for bond %zd in json_file %s\n",
				i, json_file);
		}
		ag->bonds[i].k = json_real_value(spring_constant);

		sdf_type = json_object_get(bond, "sdf_type");
		if (sdf_type != NULL) {
			if (!json_is_integer(sdf_type)) {
				fprintf(stderr,
					"json sdf_type is not integer for bond %zd in json_file %s\n",
					i, json_file);
			}
			ag->bonds[i].sdf_type = json_integer_value(sdf_type);
		} else {
			ag->bonds[i].sdf_type = 0;
		}
	}

	angles = json_object_get(base, "angles");
	if (!json_is_array(angles)) {
		fprintf(stderr, "json angles are not an array %s\n", json_file);
	}
	size_t nangles = json_array_size(angles);
	ag->nangs = nangles;
	ag->angs = _mol_calloc(nangles, sizeof(struct atomangle));
	for (size_t i = 0; i < nangles; i++) {
		json_t *angle = json_array_get(angles, i);
		if (!json_is_object(angle)) {
			fprintf(stderr,
				"Angle %zd not an object in json file %s\n", i,
				json_file);
		}
		json_t *theta, *atom1, *atom2, *atom3, *spring_constant;

		atom1 = json_object_get(angle, "atom1");
		if (!json_is_integer(atom1)) {
			fprintf(stderr,
				"json atom1 is not integer for angle %zd in json_file %s\n",
				i, json_file);
		}
		int i1 = json_integer_value(atom1) - 1;
		ag->angs[i].a0 = &(ag->atoms[i1]);
		(ag->atoms[i1].nangs)++;

		atom2 = json_object_get(angle, "atom2");
		if (!json_is_integer(atom2)) {
			fprintf(stderr,
				"json atom2 is not integer for angle %zd in json_file %s\n",
				i, json_file);
		}
		int i2 = json_integer_value(atom2) - 1;
		ag->angs[i].a1 = &(ag->atoms[i2]);
		(ag->atoms[i2].nangs)++;

		atom3 = json_object_get(angle, "atom3");
		if (!json_is_integer(atom3)) {
			fprintf(stderr,
				"json atom3 is not integer for angle %zd in json_file %s\n",
				i, json_file);
		}
		int i3 = json_integer_value(atom3) - 1;
		ag->angs[i].a2 = &(ag->atoms[i3]);
		(ag->atoms[i3].nangs)++;

		theta = json_object_get(angle, "theta");
		if (!json_is_real(theta)) {
			fprintf(stderr,
				"json theta is not floating point for angle %zd in json_file %s\n",
				i, json_file);
		}
		ag->angs[i].th0 = json_real_value(theta);

		spring_constant = json_object_get(angle, "spring_constant");
		if (!json_is_real(spring_constant)) {
			fprintf(stderr,
				"json spring_constant is not floating point for angle %zd in json_file %s\n",
				i, json_file);
		}
		ag->angs[i].k = json_real_value(spring_constant);
	}

	torsions = json_object_get(base, "torsions");
	if (!json_is_array(torsions)) {
		fprintf(stderr, "json torsions are not an array %s\n",
			json_file);
	}
	size_t ntorsions = json_array_size(torsions);
	ag->ntors = ntorsions;
	ag->tors = _mol_calloc(ntorsions, sizeof(struct atomtorsion));
	for (size_t i = 0; i < ntorsions; i++) {
		json_t *torsion = json_array_get(torsions, i);
		if (!json_is_object(torsion)) {
			fprintf(stderr,
				"Torsion %zd not an object in json file %s\n",
				i, json_file);
		}
		json_t *atom1, *atom2, *atom3, *atom4, *minima, *delta_constant,
		    *spring_constant;

		atom1 = json_object_get(torsion, "atom1");
		if (!json_is_integer(atom1)) {
			fprintf(stderr,
				"json atom1 is not integer for torsion %zd in json_file %s\n",
				i, json_file);
		}
		int i1 = json_integer_value(atom1) - 1;
		ag->tors[i].a0 = &(ag->atoms[i1]);
		(ag->atoms[i1].ntors)++;

		atom2 = json_object_get(torsion, "atom2");
		if (!json_is_integer(atom2)) {
			fprintf(stderr,
				"json atom2 is not integer for torsion %zd in json_file %s\n",
				i, json_file);
		}
		int i2 = json_integer_value(atom2) - 1;
		ag->tors[i].a1 = &(ag->atoms[i2]);
		(ag->atoms[i2].ntors)++;

		atom3 = json_object_get(torsion, "atom3");
		if (!json_is_integer(atom3)) {
			fprintf(stderr,
				"json atom3 is not integer for torsion %zd in json_file %s\n",
				i, json_file);
		}
		int i3 = json_integer_value(atom3) - 1;
		ag->tors[i].a2 = &(ag->atoms[i3]);
		(ag->atoms[i3].ntors)++;

		atom4 = json_object_get(torsion, "atom4");
		if (!json_is_integer(atom4)) {
			fprintf(stderr,
				"json atom4 is not integer for torsion %zd in json_file %s\n",
				i, json_file);
		}
		int i4 = json_integer_value(atom4) - 1;
		ag->tors[i].a3 = &(ag->atoms[i4]);
		(ag->atoms[i4].ntors)++;

		minima = json_object_get(torsion, "minima");
		if (!json_is_integer(minima)) {
			fprintf(stderr,
				"json minima is not integer for torsion %zd in json_file %s\n",
				i, json_file);
		}
		ag->tors[i].n = json_integer_value(minima);

		delta_constant = json_object_get(torsion, "delta_constant");
		if (!json_is_real(delta_constant)) {
			fprintf(stderr,
				"json delta_constant is not floating point for torsion %zd in json_file %s\n",
				i, json_file);
		}
		ag->tors[i].d = json_real_value(delta_constant);

		spring_constant = json_object_get(torsion, "spring_constant");
		if (!json_is_real(spring_constant)) {
			fprintf(stderr,
				"json spring_constant is not floating point for torsion %zd in json_file %s\n",
				i, json_file);
		}
		ag->tors[i].k = json_real_value(spring_constant);
	}

	impropers = json_object_get(base, "impropers");
	if (!json_is_array(impropers)) {
		fprintf(stderr, "json impropers are not an array %s\n",
			json_file);
	}
	size_t nimpropers = json_array_size(impropers);
	ag->nimps = nimpropers;
	ag->imps = _mol_calloc(nimpropers, sizeof(struct atomimproper));
	for (size_t i = 0; i < nimpropers; i++) {
		json_t *improper = json_array_get(impropers, i);
		if (!json_is_object(improper)) {
			fprintf(stderr,
				"Improper %zd not an object in json file %s\n",
				i, json_file);
		}
		json_t *atom1, *atom2, *atom3, *atom4, *phi, *spring_constant;

		atom1 = json_object_get(improper, "atom1");
		if (!json_is_integer(atom1)) {
			fprintf(stderr,
				"json atom1 is not integer for improper %zd in json_file %s\n",
				i, json_file);
		}
		int i1 = json_integer_value(atom1) - 1;
		ag->imps[i].a0 = &(ag->atoms[i1]);
		(ag->atoms[i1].nimps)++;

		atom2 = json_object_get(improper, "atom2");
		if (!json_is_integer(atom2)) {
			fprintf(stderr,
				"json atom2 is not integer for improper %zd in json_file %s\n",
				i, json_file);
		}
		int i2 = json_integer_value(atom2) - 1;
		ag->imps[i].a1 = &(ag->atoms[i2]);
		(ag->atoms[i2].nimps)++;

		atom3 = json_object_get(improper, "atom3");
		if (!json_is_integer(atom3)) {
			fprintf(stderr,
				"json atom3 is not integer for improper %zd in json_file %s\n",
				i, json_file);
		}
		int i3 = json_integer_value(atom3) - 1;
		ag->imps[i].a2 = &(ag->atoms[i3]);
		(ag->atoms[i3].nimps)++;

		atom4 = json_object_get(improper, "atom4");
		if (!json_is_integer(atom4)) {
			fprintf(stderr,
				"json atom4 is not integer for improper %zd in json_file %s\n",
				i, json_file);
		}
		int i4 = json_integer_value(atom4) - 1;
		ag->imps[i].a3 = &(ag->atoms[i4]);
		(ag->atoms[i4].nimps)++;

		phi = json_object_get(improper, "phi");
		if (!json_is_real(phi)) {
			fprintf(stderr,
				"json phi is not floating point for improper %zd in json_file %s\n",
				i, json_file);
		}
		ag->imps[i].psi0 = json_real_value(phi);

		spring_constant = json_object_get(improper, "spring_constant");
		if (!json_is_real(spring_constant)) {
			fprintf(stderr,
				"json spring_constant is not floating point for improper %zd in json_file %s\n",
				i, json_file);
		}
		ag->imps[i].k = json_real_value(spring_constant);
	}

	json_decref(base);

//allocate atom arrays of pointers to parameters
	for (size_t i = 0; i < natoms; i++) {
		int i1 = ag->atoms[i].nbonds;
		ag->atoms[i].bonds = _mol_calloc(i1, sizeof(struct atombond *));
		ag->atoms[i].nbonds = 0;
		i1 = ag->atoms[i].nangs;
		ag->atoms[i].angs = _mol_calloc(i1, sizeof(struct atomangle *));
		ag->atoms[i].nangs = 0;
		i1 = ag->atoms[i].ntors;
		ag->atoms[i].tors =
		    _mol_calloc(i1, sizeof(struct atomtorsion *));
		ag->atoms[i].ntors = 0;
		i1 = ag->atoms[i].nimps;
		ag->atoms[i].imps =
		    _mol_calloc(i1, sizeof(struct atomimproper *));
		ag->atoms[i].nimps = 0;
	}
	struct atom *atm;
//fill bonds
	for (int i = 0; i < ag->nbonds; i++) {
		atm = ag->bonds[i].a0;
		atm->bonds[(atm->nbonds)++] = &(ag->bonds[i]);
		atm = ag->bonds[i].a1;
		atm->bonds[(atm->nbonds)++] = &(ag->bonds[i]);
	}
//fill angles
	for (int i = 0; i < ag->nangs; i++) {
		atm = ag->angs[i].a0;
		atm->angs[(atm->nangs)++] = &(ag->angs[i]);
		atm = ag->angs[i].a1;
		atm->angs[(atm->nangs)++] = &(ag->angs[i]);
		atm = ag->angs[i].a2;
		atm->angs[(atm->nangs)++] = &(ag->angs[i]);
	}
//fill torsions
	for (int i = 0; i < ag->ntors; i++) {
		atm = ag->tors[i].a0;
		atm->tors[(atm->ntors)++] = &(ag->tors[i]);
		atm = ag->tors[i].a1;
		atm->tors[(atm->ntors)++] = &(ag->tors[i]);
		atm = ag->tors[i].a2;
		atm->tors[(atm->ntors)++] = &(ag->tors[i]);
		atm = ag->tors[i].a3;
		atm->tors[(atm->ntors)++] = &(ag->tors[i]);
	}
//fill impropers
	for (int i = 0; i < ag->nimps; i++) {
		atm = ag->imps[i].a0;
		atm->imps[(atm->nimps)++] = &(ag->imps[i]);
		atm = ag->imps[i].a1;
		atm->imps[(atm->nimps)++] = &(ag->imps[i]);
		atm = ag->imps[i].a2;
		atm->imps[(atm->nimps)++] = &(ag->imps[i]);
		atm = ag->imps[i].a3;
		atm->imps[(atm->nimps)++] = &(ag->imps[i]);
	}
//atom indices in the group
	fill_ingrp(ag);

	ag->is_psf_read = true;

	// copy vals from deprecated to new data structures
	int atomsi;
	for (atomsi = 0; atomsi < ag->natoms; atomsi++) {
		_mol_atom_create_bond_indices(&ag->atoms[atomsi],
					      ag->atoms[atomsi].nbonds);
	}
	_mol_atom_group_copy_from_deprecated(ag);
	return ag;
}
コード例 #4
0
int main(int argc, char* argv[]){

	// Input Files //
	/* Intro Message */
                printf("\n");
                printf("A Program to Repack Protein Side-chains for Protein Docking Refinement Procedures\n");
                printf("Copyright (c) 2014, Structural Bioinformatics Laboratory, Boston University\n");
                printf("Author: Mohammad Moghadasi ([email protected]) \n");	

	if(argc!=10){
		printf("Usage:\n ./main \n   Complex_IN.pdb Complex_IN.psf Complex_IN.mol2 Complex_IN_Ligand.pdb\n   Libmol-param-file charmm-param-file.prm  charmm-rtf-file.rtf rotamer-library-binary-file.txt\n   Complex_OUT.pdb\n \n");
		exit(EXIT_FAILURE);
	}

        char* ifile           = argv[1];       //pdb file of both receptor and ligand
        char* psffile         = argv[2];         //charmm type psf file
        char* mol2file        = argv[3];         //mol2 file
        char* pdbfilelig      = argv[4];         //pdb file of ligand
        char* atom_prm_file   = argv[5];         //libmol parameter file
              prmfile         = argv[6];         //charmm type parameter file
              rtffile         = argv[7];         //charmm type connectivity file
        char* rotamer_library_file  = argv[8]; //rotamer raw library file
        char* ofile           = argv[9];         //output file
	
	// Filling the atom_group struct //

	struct prm *atomprm    = read_prm(atom_prm_file,_MOL_VERSION_);
	struct atomgrp* ag     = read_file_atomgrp(ifile, atomprm, -1);
	read_ff_charmm(psffile, prmfile, rtffile, ag);

	if(!read_hybridization_states_from_mol2(mol2file,ag)){
	    exit (EXIT_FAILURE);             
	}                 
        fix_acceptor_bases(ag,atomprm);

        struct List lig_list;
	read_fix(pdbfilelig,&lig_list.n,&lig_list.K);

	fixed_init(ag);
        fixed_update_unfreeze_all(ag);
        zero_grads(ag);
        fill_ingrp(ag);

	struct agsetup* ags;
        ags     = malloc(sizeof(struct agsetup));
        init_nblst(ag,ags);
        update_nblst(ag,ags);

	// Mark interface residues //
	
        int num_of_res_interface;
        int res_list_interface[ag->nres];
        mark_interface_residues(ag,ags,lig_list, lig_rec_dist ,&num_of_res_interface,res_list_interface);

	// Initialize side chain rotamer library  //
	
	//nrotCoef = 3;
	nrotCoef = 1;
	MAX_ROT = 245;
	MAX_RES = ag->nres;//needed for full_pack
        cutoff = 3;

	// Reslist // 

	struct ifres_list* reslist;
	ifres_list_malloc( &reslist );
	reslist->num_of_ifres = num_of_res_interface;
	for(int r = 0; r < reslist->num_of_ifres ; r++)
		reslist->ifres_num[r] = res_list_interface[r];

	// Library //

	char *rotamer_lib;
	load_file_to_memory(rotamer_library_file, &rotamer_lib);
	struct rot_info *rotinf;
	init_rotinf(ag, num_of_res_interface, res_list_interface, rotamer_lib, &rotinf);

	struct ifres_list* reslist_minor;
	ifres_list_malloc( &reslist_minor ) ;

	// MAIN FUNCITION // 
	//
	clock_t start, finish;
	start = clock();

	full_pack(ag,lig_list,rotinf,num_of_res_interface, reslist_minor);

	finish = clock();
	if(0) printf("Processing Time = %f\n",((double)(finish-start)/CLOCKS_PER_SEC));

	// Writing the atom_group into a PDB //

	write_pdb_traj_nopar(ag,ifile,ofile);
	
	// Free memory //
        Free_ifres_list( &reslist_minor );	
	free(rotamer_lib);

	return 0;
}