/*
FILE:     harv.h
*/
/*
VERSION:  1.600
*/
/*
DATE:     2/3/2005
*/
/*
  Comments and Questions to: sw-help@rcsb.rutgers.edu
*/
/*
COPYRIGHT 1999-2005 Rutgers - The State University of New Jersey

This software is provided WITHOUT WARRANTY OF MERCHANTABILITY OR
FITNESS FOR A PARTICULAR PURPOSE OR ANY OTHER WARRANTY, EXPRESS OR
IMPLIED.  RUTGERS MAKE NO REPRESENTATION OR WARRANTY THAT THE
SOFTWARE WILL NOT INFRINGE ANY PATENT, COPYRIGHT OR OTHER
PROPRIETARY RIGHT.

The user of this software shall indemnify, hold harmless and defend
Rutgers, its governors, trustees, officers, employees, students,
agents and the authors against any and all claims, suits,
losses, liabilities, damages, costs, fees, and expenses including
reasonable attorneys' fees resulting from or arising out of the
use of this software.  This indemnification shall include, but is
not limited to, any and all claims alleging products liability.
*/
/*
               PDB SOFTWARE LICENSE AGREEMENT

BY CLICKING THE ACCEPTANCE BUTTON OR INSTALLING OR USING 
THIS "SOFTWARE, THE INDIVIDUAL OR ENTITY LICENSING THE  
SOFTWARE ("LICENSEE") IS CONSENTING TO BE BOUND BY AND IS 
BECOMING A PARTY TO THIS AGREEMENT.  IF LICENSEE DOES NOT 
AGREE TO ALL OF THE TERMS OF THIS AGREEMENT
THE LICENSEE MUST NOT INSTALL OR USE THE SOFTWARE.

1. LICENSE AGREEMENT

This is a license between you ("Licensee") and the Protein Data Bank (PDB) 
at Rutgers, The State University of New Jersey (hereafter referred to 
as "RUTGERS").   The software is owned by RUTGERS and protected by 
copyright laws, and some elements are protected by laws governing 
trademarks, trade dress and trade secrets, and may be protected by 
patent laws. 

2. LICENSE GRANT

RUTGERS grants you, and you hereby accept, non-exclusive, royalty-free 
perpetual license to install, use, modify, prepare derivative works, 
incorporate into other computer software, and distribute in binary 
and source code format, or any derivative work thereof, together with 
any associated media, printed materials, and on-line or electronic 
documentation (if any) provided by RUTGERS (collectively, the "SOFTWARE"), 
subject to the following terms and conditions: (i) any distribution 
of the SOFTWARE shall bind the receiver to the terms and conditions 
of this Agreement; (ii) any distribution of the SOFTWARE in modified 
form shall clearly state that the SOFTWARE has been modified from 
the version originally obtained from RUTGERS.  

2. COPYRIGHT; RETENTION OF RIGHTS.  

The above license grant is conditioned on the following: (i) you must 
reproduce all copyright notices and other proprietary notices on any 
copies of the SOFTWARE and you must not remove such notices; (ii) in 
the event you compile the SOFTWARE, you will include the copyright 
notice with the binary in such a manner as to allow it to be easily 
viewable; (iii) if you incorporate the SOFTWARE into other code, you 
must provide notice that the code contains the SOFTWARE and include 
a copy of the copyright notices and other proprietary notices.  All 
copies of the SOFTWARE shall be subject to the terms of this Agreement.  

3. NO MAINTENANCE OR SUPPORT; TREATMENT OF ENHANCEMENTS 

RUTGERS is under no obligation whatsoever to: (i) provide maintenance 
or support for the SOFTWARE; or (ii) to notify you of bug fixes, patches, 
or upgrades to the features, functionality or performance of the 
SOFTWARE ("Enhancements") (if any), whether developed by RUTGERS 
or third parties.  If, in its sole discretion, RUTGERS makes an 
Enhancement available to you and RUTGERS does not separately enter 
into a written license agreement with you relating to such bug fix, 
patch or upgrade, then it shall be deemed incorporated into the SOFTWARE 
and subject to this Agreement. You are under no obligation whatsoever 
to provide any Enhancements to RUTGERS or the public that you may 
develop over time; however, if you choose to provide your Enhancements 
to RUTGERS, or if you choose to otherwise publish or distribute your 
Enhancements, in source code form without contemporaneously requiring 
end users or RUTGERS to enter into a separate written license agreement 
for such Enhancements, then you hereby grant RUTGERS a non-exclusive,
royalty-free perpetual license to install, use, modify, prepare
derivative works, incorporate into the SOFTWARE or other computer
software, distribute, and sublicense your Enhancements or derivative
works thereof, in binary and source code form.

4. FEES.  There is no license fee for the SOFTWARE.  If Licensee
wishes to receive the SOFTWARE on media, there may be a small charge
for the media and for shipping and handling.  Licensee is
responsible for any and all taxes.

5. TERMINATION.  Without prejudice to any other rights, Licensor
may terminate this Agreement if Licensee breaches any of its terms
and conditions.  Upon termination, Licensee shall destroy all
copies of the SOFTWARE.

6. PROPRIETARY RIGHTS.  Title, ownership rights, and intellectual
property rights in the Product shall remain with RUTGERS.  Licensee 
acknowledges such ownership and intellectual property rights and will 
not take any action to jeopardize, limit or interfere in any manner 
with RUTGERS' ownership of or rights with respect to the SOFTWARE.  
The SOFTWARE is protected by copyright and other intellectual 
property laws and by international treaties.  Title and related 
rights in the content accessed through the SOFTWARE is the property 
of the applicable content owner and is protected by applicable law.  
The license granted under this Agreement gives Licensee no rights to such
content.

7. DISCLAIMER OF WARRANTY.  THE SOFTWARE IS PROVIDED FREE OF 
CHARGE, AND, THEREFORE, ON AN "AS IS" BASIS, WITHOUT WARRANTY OF 
ANY KIND, INCLUDING WITHOUT LIMITATION THE WARRANTIES THAT IT 
IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE 
OR NON-INFRINGING.  THE ENTIRE RISK AS TO THE QUALITY AND 
PERFORMANCE OF THE SOFTWARE IS BORNE BY LICENSEE.  SHOULD THE 
SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, THE LICENSEE AND NOT 
LICENSOR ASSUMES THE ENTIRE COST OF ANY SERVICE AND REPAIR.  
THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF 
THIS AGREEMENT.  NO USE OF THE PRODUCT IS AUTHORIZED HEREUNDER 
EXCEPT UNDER THIS DISCLAIMER.

8. LIMITATION OF LIABILITY.  TO THE MAXIMUM EXTENT PERMITTED BY
APPLICABLE LAW,  IN NO EVENT WILL LICENSOR BE LIABLE FOR ANY 
INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 
OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, INCLUDING, 
WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK 
STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL 
OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF ADVISED OF THE
POSSIBILITY THEREOF. 
*/
# define FREE_ARG char*
# define NR_END 1
# define DATA_BLOCK "UNNAMED"

struct cif_items
{
    char **category, **items;
    int ncat, nitem;
};

void reorder_shell(int argc, char **argv, char *inpfile);

void parse_adit_text_to_mmcif(FILE *fout, char *inpfile);
void extract_seq (int argc, char **argv);


void proc_nmr_structure(char *outfile, int argc, char **argv);

void for_phasing(FILE *fout,char *prog,char *filename,char *format,
                 char *method);
void for_dm(FILE *fout, char *prog, char *filename, char *format,
            char *method);
void for_refine(FILE *fout, char *prog,char *filename, char *format,
                char *method);
void for_mr(FILE *fout, char *progname, char *filename, char *format,
            char *method);
void cifparse(char *iFile, char *oFile, int width);
void unknown_prog(FILE *fout, char *inpfile, char *format, char *method);
void check_input_error(int argc, char **argv, char *method,char *method_mr,
                       char *heavy_prog);
void write_cif_or_pdb(FILE *fout,  char *inpfile, char *format, char *method);
void read_entity_poly(FILE *fout, int argc, char **argv, char *method);

void extraction(FILE *fout, int argc, char **argv, char *method,
                char *option_id, char *step_id);
void process_files(FILE *fout, int *j, int argc, char **argv,
                   char *prog, char *format,  char *method, char *id);
void rewrite_cif(char *inpfile);
long lowerstr(char *a);
int pdb_cif_file(int i, int argc, char **argv);
int check_block(char *str);
void phasing_category_head(FILE *fout, char *category, char *items);
char ** get_cif_items(char *inpfile, int *nitem);
int item_compare(char **cate, int m, char *items);
void write_cif_tmp(char *inpfile);

void read_ENTITY_file(FILE *fout, char *inpfile);
void usage();
void delete_prime(char *str);
void guess_pdb_format(char *inpfile, int *pdb);
void heavy_coord_pdb(FILE *fout, char *inpfile, char *method);
void delete_return_char(char *str);

void get_software_info(FILE *fout, int argc, char **argv);
void for_mr(FILE *fout, char *prog, char *infile, char *format, char *method);
void write_block_method(FILE *fout, char *method,char *method_mr,
                        int argc, char **argv);

//pdb2cif
void pdb_2_cif(FILE *fout, char *inpfile);


/*CNS*/

void CNS_phase_file_assign(FILE *fout,char *inpfile,char *format,char *method);
void CNS_phasing_DM(FILE *fout, char inpfile[], char *format, char method[]);
void CNS_phasing_wave(FILE *fout, char inpfile[], char method[]);
void CNS_phasing(FILE *fout, char *inpfile, char *method);
void CNS_heavy_cood(FILE *fout, char inpfile[], char method[]);
void CNS_final_struct_ref(FILE *fout, char inpfile[], char *file_format,
                          char method[]);
void CNS_fom(FILE *fout, char inpfile[], char method[]);
void CNS_each_item(FILE *fp, char *item,float *v1, 
                   float *v2, float *v3, float *v4,float *v5,long *ns, 
                   float *sh1,float *sh2,float *sh3,float *sh4,float *sh5);
void write_CNS_heavy_xyz(FILE *fout, char *str,const  char *start,const  char *end);

void CNS_mr(FILE *fout, char *inpf,char *format, char *method);
void EPMR_mr(FILE *fout, char *inpf,char *format, char *method);

/*CCP4*/

void CCP4_phase_file_assign(FILE *fout, char *inpf,char *format,char *method);
void CCP4_MAD_wave(FILE *fout, char inpfile[], char method[]);
void CCP4_mlphare_cif(FILE *fout, char inpfile[], char method[]);
void CCP4_ref_refmac5(FILE *fout,char *inpfi,char *file_format,char *method);
void CCP4_ref_restrain(FILE *fout,char *inpfi,char *file_format,char *method);
void CCP4_refine(FILE *fout, char inpfile[], char method[]);
void CCP4_phasing_DM(FILE *fout, char inpfile[],char *format, char method[]);
void CCP4_phasing_SOLOMON(FILE *fout, char *inpf,char *format, char *method);
void CCP4_amore(FILE *fout, char *inpf,char *format, char *method);
void CCP4_molrep(FILE *fout, char *inpf,char *format, char *method);

/*SOLVE*/
void SOLVE_phase(FILE *fout, char *inpfile, char *format, char *method);
void SOLVE_phasing_wave(FILE *fout, char *inpfile, char *method);
void SOLVE_heavy_cood(FILE *fout, char *inpfile, char *method);
void SOLVE_phasing_stat(FILE *fout, char *inpfile, char *method);
void SOLVE_phasing_DM(FILE *fout, char *inpfile,char *format, char *method);

/*SHARP*/
void SHARP_phase(FILE *fout, char *inpfile, char *fomrat, char *method);
void SHARP_phasing_wave(FILE *fout, char *inpfile, char *method);
void SHARP_heavy_cood(FILE *fout, char *inpfile, char *method);
void SHARP_phasing_stat(FILE *fout, char *inpfile, char *method);
void SHARP_stat(char *inpfile, char *id,float rc_c[80][30], float rc_a[80][30],
                char **head,float *all_a,float *all_c,int *nshell,int *nitem);
void SHARP_stat_fom(FILE *fout, char *inpfile, char *method);
void SHARP_phasing_DM(FILE *fout, char *inpfile, char *format,char *method);
void SHARP_phasing_stat_v2(FILE *fout, char *inpfile, char *method);

void get_data_sharp_v2(FILE *fp,  char *rc, double **res_L, double **res_H, 
                       double **rc_ai, double **rc_ci, double **rc_aa,
                       double **rc_ca,double *rc_ai_all,double *rc_ci_all,
                       double *rc_aa_all,double *rc_ca_all,long nba,long *nb);


/*SHELX*/
void SHELX_final_struct_ref(FILE *fout,char *inpfil,char *format,char *method);
void SHELX_phase(FILE *fout, char *inpfile, char *method, char *id);
void SHELX_pdb_head(FILE *fout, char *inpfile);
void SHELX_log(FILE *fout, char *inpfile);

/*TNT*/
void TNT_cell_orig_scale(FILE *fout, char *inpfile);
void TNT_sys_ref(FILE *fout, char *inpfile);
void TNT_final_struct_ref(FILE *fout,char *inpfile, char *format,char *method);

/*WARP*/
void WARP_refine(FILE *fout, char inpfile[], char *file_format,char method[]);
void WARP_cell_orig_scale(FILE *fout, char *inpfile);
void warp_refine_log(FILE *fout, char *inpfile);


/*SNB or BNP*/
void SNB_phase(FILE *fout, char *inpfile, char *method, char *id);
void BNP_phase(FILE *fout, char *inpfile, char *method, char *id);


/* For Scale */


void write_mmCIF(FILE *fout, int argc, char **argv);
void extraction_new(FILE *fout, int argc, char **argv);
void extract_scale(FILE *fout, int argc, char **argv, int start, char *prog);
void extract_scale_phase(FILE *fout, int argc, char **argv, int start, char *prog);
void extract_index(FILE *fout, int argc, char **argv, int start, char *prog);
void extract_HKL_log( char *inpfile );
void extract_DTREK_log(char *inpfile );
void extract_SAINT_log(char *inpfile );
void extract_SCALA_log(char *inpfile );
void extract_3DSCALE_log(char *inpfile );
void write_reflns(FILE *fout);
void write_reflns_shell(FILE *fout);
void initial_reflns(void);
void extract_HKL_log_index( char *inpfile );
void extract_DTREK_log_index(char *infile); 
void extract_MOSFLM_log_index(char *infile); 
void CCP4_phaser(FILE *fout, char *inpfile,char *format, char *method);
int type_of_data_template(char *infile);
