Пример #1
0
/* print the graph of buckets and quantities */
void
print_bucket_graph(row_buckets_t *graph_buckets, char *label, 
	                    int graph_values[]) {
	int i, j;
	/* calculates a scale factor for the graph */
	int scale = find_scale_factor(graph_values);
	printf("graph of %s, scaled by a factor of %d\n", label, scale);
	for(i=GRAPHROWS-1; i>=0; i--) {
		/* this formatting here assumes that values of the buckets are 
		   not larger than 999.99 - as instructed by tutor, this is a 
		   safe assumption */
		printf("%6.2f--%6.2f [%3d]:", graph_buckets->buckets[i], 
			    graph_buckets->buckets[i] + 
			    graph_buckets->bucket_step_size, graph_values[i]);
		/* scales the characters printed to 60 column maximum */
		/* as graph row will actually overflow if 60 characters are 
		   printed, require that no more than 59 are printed */
		for(j=1; (j<=GRAPHCOLS-1) && 
			        (j<=ceil((double)graph_values[i]/scale)); j++) {
			printf("*");
		}
		printf("\n");

	}
}
Пример #2
0
int surface_dimer_parameters(system_t *system, param_g *params) {

	int i = 0; // generic counter
	
	molecule_t *molecule_ptr;
	atom_t *atom_ptr;
	param_t *param_ptr;
	
	// Default bond partner for atoms without explicit site neighbor
	atom_t *origin = calloc( sizeof(atom_t), 1 ); // calloc sets pos[] fields all to 0
	memnullcheck( origin, sizeof(atom_t), __LINE__-1, __FILE__);

	system->polar_damp = params->alpha;

	for (molecule_ptr = system->molecules; molecule_ptr; molecule_ptr = molecule_ptr->next) {
	
		for (atom_ptr = molecule_ptr->atoms; atom_ptr; atom_ptr = atom_ptr->next) {
	
			for (param_ptr = params->type_params; param_ptr; param_ptr = param_ptr->next) {
	
				if( !strcasecmp( param_ptr->atomtype, atom_ptr->atomtype )) {

					atom_ptr->charge  = param_ptr->charge;
					atom_ptr->epsilon = param_ptr->epsilon;
					atom_ptr->sigma   = param_ptr->sigma;
					atom_ptr->omega   = param_ptr->omega;
					atom_ptr->polarizability = param_ptr->pol;
					atom_ptr->c6 = param_ptr->c6;
					atom_ptr->c8 = param_ptr->c8;
					atom_ptr->c10 = param_ptr->c10;

					double perturbation_vector[3];

					// Find the the atom that defines the bond axis and store for easy reference
					atom_t *snPtr = 0;
					if( atom_ptr->site_neighbor_id == 0 )
						snPtr = origin;
					else {
						snPtr = find_atom_by_id( system, atom_ptr->site_neighbor_id );
						if( !snPtr ) {
							snPtr = origin;
							printf( "\n*** WARNING ***\n" );
							printf( "Bonding partner for atom %d not found ",      atom_ptr->bond_id );
							printf( "--> %d, possibly invalid. Using origin.\n\n", atom_ptr->site_neighbor_id );
						}
					}

					// Generate the vector along which the dr perturbations will occur
					for (i = 0; i < 3; i++)
						perturbation_vector[i] = atom_ptr->pos[i] - snPtr->pos[i];

					// Determine how much the bond vector should be scaled to increase the length by dr.
					double scale = find_scale_factor(perturbation_vector[0], perturbation_vector[1], perturbation_vector[2], param_ptr->dr);
					
					// Scale the perturbation vector
					for (i = 0; i < 3; i++)
						perturbation_vector[i] *= scale;
					
					// Add the vector back to the bond partner coordinates to get the new position.
					for (i = 0; i < 3; i++)
						atom_ptr->pos[i] = snPtr->pos[i] + perturbation_vector[i];

				}
			} // for param_ptr
		} // for atom_ptr
	} // for molecule_ptr

	free(origin);

	return (0);
}